1. Waldemar Kornewald
  2. djangotoolbox

Commits

fhahn  committed 612f0be

add field fk_list with current fks of permission objects to UserPermissionList and GroupPermissionList for simpler admin form generation

  • Participants
  • Parent commits 3f00ed0
  • Branches default

Comments (0)

Files changed (3)

File djangotoolbox/auth/backends.py

View file
  • Ignore whitespace
                 if len(group_ids) > 0:
                     group_permissions = set()
                     group_permissions.update(GroupPermissionList.objects.filter(group__id__in=gl.fk_list))
-                for group_perm in group_permissions:
-                    perms.update(group_perm.permission_list)
+                    for group_perm in group_permissions:
+                        perms.update(group_perm.permission_list)
                     
             except GroupList.DoesNotExist:
                 pass

File djangotoolbox/auth/models.py

View file
  • Ignore whitespace
 class UserPermissionList(models.Model):
     user = models.ForeignKey(User)
     permission_list = ListField(models.CharField(max_length=128))
-
+    fk_list = ListField(models.PositiveIntegerField())
 
 class GroupPermissionList(models.Model):
     group = models.ForeignKey(Group)
     permission_list = ListField(models.CharField(max_length=128))
+    fk_list = ListField(models.PositiveIntegerField())
 
 
 class GroupList(models.Model):

File djangotoolbox/auth/utils.py

View file
  • Ignore whitespace
 
     old_perms = list_obj.permission_list
 
-    perm_strs = ['%s.%s' % (perm.content_type.app_label, perm.codename) for perm in perm_objs]
+    perm_strs = [['%s.%s' % (perm.content_type.app_label, perm.codename), perm.id] for perm in perm_objs]
 
     for perm in old_perms:
         try: 
             perm_strs.index(perm)
         except ValueError:
-            list_obj.permission_list.remove(perm)
+            i = list_obj.permission_list.index(perm)
+            list_obj.permission_list.pop(i)
+            list_obj.fk_list.pop(i)
 
     for perm in perm_strs:
         try:
-            old_perms.index(perm)
+            old_perms.index(perm[0])
         except ValueError:
-            list_obj.permission_list.append(perm)
-
+            list_obj.permission_list.append(perm[0])
+            list_obj.fk_list.append(perm[1])
+            
     if len(perm_strs) == 0:
         list_obj.permission_list = []
+        list_obj.fk_list = []
         
     list_obj.save()