Commits

Anonymous committed 95438e1

ModelBackend uses new properties groups and user_permissions

Comments (0)

Files changed (1)

djangotoolbox/contrib/auth/backends.py

         groups.
         """
         if not hasattr(user_obj, '_group_perm_cache'):
-            # get all Group objects, a user is member of
-            group_ids = user_obj.group_list.groups
-
-            if len(group_ids) > 0:
-                q = Group.objects.filter(id__in=group_ids)
-            else:
-                q = list()
-                
+                  
             perm_ids = set()
-            for group in q:
+            for group in user_obj.groups:
                 perm_ids.update(group.permissions.permissions)
 
             if len(perm_ids) > 0:
             else:
                 q = list()
                 
-            perms = list()        
-            for perm in q:
-                perms.append([perm.content_type.app_label, perm.codename])
+            perms = list([[perm.content_type.app_label, perm.codename] for perm in q])
   
             user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms])
         return user_obj._group_perm_cache
         if user_obj.is_anonymous():
             return set()
         if not hasattr(user_obj, '_perm_cache'):
-            perm_ids = user_obj.user_permissions.permissions
-            if len(perm_ids) > 0:
-                q = Permission.objects.filter(id__in=perm_ids)
-            else:
-                q = list()
-            
-            user_obj._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in q])
+            user_obj._perm_cache = set([u"%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions])
             user_obj._perm_cache.update(self.get_group_permissions(user_obj))
         return user_obj._perm_cache