Florian Hahn avatar Florian Hahn committed 600d255

add group field to GroupObjectPermissionAdmin

Comments (0)

Files changed (1)

object_permission_backend_nonrel/admin.py

     def save_model(self, request, obj, form, change):
         if form.is_valid():
             obj.permissions = form.cleaned_data['obj_permission_list']
-            obj.user_id = form.cleaned_data['user']
         super(BaseObjectPermissionAdmin, self).save_model(request, obj, form, change)
 
 
 class ObjectPermissionAdmin(BaseObjectPermissionAdmin):
     form = ObjectPermissionForm
 
+    def save_model(self, request, obj, form, change):
+        if form.is_valid():
+            obj.user_id = form.cleaned_data['user']
+        super(ObjectPermissionAdmin, self).save_model(request, obj, form, change)
 
+        
 class GroupObjectPermissionForm(BaseObjectPermissionForm):
      obj_permission_list = forms.MultipleChoiceField(required=False)
-     
+     group = forms.ChoiceField(required=True)
 
+     def __init__(self, *args, **kwargs):
+        super(GroupObjectPermissionForm, self).__init__(*args, **kwargs)        
+        groups = Group.objects.all()
+        choices = [[group.id, group.name] for group in groups]
+        self.fields['group'].choices = choices
+        try:
+            self.fields['group'].initial = kwargs['instance'].group_id
+        except KeyError:
+            pass
+        
      class Meta:
          model = GroupObjectPermission
-         exclude = ('permissions')
+         exclude = ('permissions', 'group_id')
 
 
 class GroupObjectPermissionAdmin(BaseObjectPermissionAdmin):
     form = GroupObjectPermissionForm
 
+    def save_model(self, request, obj, form, change):
+        if form.is_valid():
+            obj.group_id = form.cleaned_data['group']
+        super(GroupObjectPermissionAdmin, self).save_model(request, obj, form, change)
 
+        
 class PermissionTypeAdmin(admin.ModelAdmin):
     pass
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.