Anonymous avatar Anonymous committed 6756084

permission and group forms are displayed, if AUTHENTICATION_BACKENDS contains djangotoolbox.auth.backends.NonrelPermissionBackend

Comments (0)

Files changed (1)

djangotoolbox/admin.py

+import settings
 from django import forms
 from django.contrib import admin
 from django.contrib.auth.admin import UserAdmin
 from djangotoolbox.auth.models import UserPermissionList, GroupList, \
      GroupPermissionList
 
+class UserForm(forms.ModelForm):
+    class Meta:
+        model = User
+        fields = ('username', 'email', 'first_name', 'last_name', 'is_active',
+                  'is_staff', 'is_superuser')
 
-class UserForm(forms.ModelForm):
+
+class NonrelPermissionUserForm(UserForm):
     permissions = forms.MultipleChoiceField(required=False)
     groups = forms.MultipleChoiceField(required=False)
     
         except (GroupList.DoesNotExist, KeyError):
             self.fields['groups'].initial = list()
                                     
-    class Meta:
-        model = User
-        fields = ('username', 'email', 'first_name', 'last_name', 'is_active',
-                  'is_staff', 'is_superuser',)
-
 
 class CustomUserAdmin(UserAdmin):
     fieldsets = None
     form = UserForm
     
+
+class NonrelPermissionCustomUserAdmin(UserAdmin):
+    fieldsets = None
+    form = NonrelPermissionUserForm
+    
     def save_model(self, request, obj, form, change):
         super(CustomUserAdmin, self).save_model(request, obj, form, change)
 
             groups = list()
 
         update_user_groups(obj, groups)
-                
+
+
 class PermissionAdmin(admin.ModelAdmin):
     ordering = ('name',)
 
 
 admin.site.unregister(User)
 admin.site.unregister(Group)
-admin.site.register(Group, CustomGroupAdmin)
-admin.site.register(User, CustomUserAdmin)
-admin.site.register(Permission, PermissionAdmin)
+
+nonrel_backend = False
+backends = getattr(settings, 'AUTHENTICATION_BACKENDS', list())
+for backend in backends:
+    if backend ==  'djangotoolbox.auth.backends.NonrelPermissionBackend':
+        nonrel_backend = True
+
+if nonrel_backend:
+    admin.site.register(User, NonrelPermissionCustomUserAdmin)
+    admin.site.register(Permission, PermissionAdmin)
+    admin.site.register(Group, CustomGroupAdmin)
+else:
+    admin.site.register(User, CustomUserAdmin)
+
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.