Commits

Florian Hahn committed 9752c70

add form field for user to ObjectPermissionForm

Comments (0)

Files changed (1)

object_permission_backend_nonrel/admin.py

 
 class ObjectPermissionForm(BaseObjectPermissionForm):
     obj_permission_list = forms.MultipleChoiceField(required=False)
+    user = forms.ChoiceField(required=True)
 
-            
+    def __init__(self, *args, **kwargs):
+        super(ObjectPermissionForm, self).__init__(*args, **kwargs)        
+        users = User.objects.all()
+        choices = [[user.id, user.username] for user in users]
+        self.fields['user'].choices = choices
+        try:
+            self.fields['user'].initial = kwargs['instance'].user_id
+        except KeyError:
+            pass
+
     class Meta:
         model = ObjectPermission
-        exclude = ('permissions')
+        exclude = ('permissions', 'user_id')
 
 
 class BaseObjectPermissionAdmin(admin.ModelAdmin):
 admin.site.register(ObjectPermission, ObjectPermissionAdmin)
 admin.site.register(GroupObjectPermission, GroupObjectPermissionAdmin)
 admin.site.register(PermissionType, PermissionTypeAdmin)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+