AttrCASBackend: Save user instance only when necessary 0.1.19
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 9 Jun 2014 12:27:34 +0000 (14:27 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Mon, 9 Jun 2014 12:27:34 +0000 (14:27 +0200)
fnpdjango/auth_backends.py
setup.py

index 3cd60a7..7a89c1a 100644 (file)
@@ -10,13 +10,17 @@ attr_map = getattr(settings, 'CAS_USER_ATTRS_MAP', {
 class AttrCASBackend(CASBackend):
     def authenticate(self, ticket, service, request):
         user = super(AttrCASBackend, self).authenticate(ticket, service, request)
 class AttrCASBackend(CASBackend):
     def authenticate(self, ticket, service, request):
         user = super(AttrCASBackend, self).authenticate(ticket, service, request)
+        dirty = False
         for attr, value in request.session.get('attributes', {}).items():
             try:
                 local_attr = attr_map[attr]
             except KeyError:
                 pass
             else:
         for attr, value in request.session.get('attributes', {}).items():
             try:
                 local_attr = attr_map[attr]
             except KeyError:
                 pass
             else:
-                setattr(user, local_attr, value)
-        user.save()
+                if getattr(user, local_attr, None) != value:
+                    setattr(user, local_attr, value)
+                    dirty = True
+        if dirty:
+            user.save()
         return user
 
         return user
 
index 080b75b..8f1806b 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def whole_trees(package_dir, paths):
 
 setup(
     name='fnpdjango',
 
 setup(
     name='fnpdjango',
-    version='0.1.18',
+    version='0.1.19',
     author='Radek Czajka',
     author_email='radekczajka@nowoczesnapolska.org.pl',
     url = '',
     author='Radek Czajka',
     author_email='radekczajka@nowoczesnapolska.org.pl',
     url = '',