Browse Source

petites améliorations de l’interface

Élie Bouttier 8 years ago
parent
commit
93978532ec
3 changed files with 21 additions and 7 deletions
  1. 12 1
      accounts/admin.py
  2. 1 5
      adhesions/admin.py
  3. 8 1
      adhesions/models.py

+ 12 - 1
accounts/admin.py

@@ -25,7 +25,18 @@ class UserAdmin(AuthUserAdmin):
 
     def get_fieldsets(self, request, obj=None):
         if request.user.is_superuser:
-            return super().get_fieldsets(request, obj)
+            return (
+                AuthUserAdmin.fieldsets[0],
+                AuthUserAdmin.fieldsets[1],
+                (AuthUserAdmin.fieldsets[2][0], {
+                    'classes': ('collapse',),
+                    'fields': ('is_active', 'is_staff', 'is_superuser', 'groups',), # removing of user_permissions
+                }),
+                (AuthUserAdmin.fieldsets[3][0], {
+                    'classes': ('collapse',),
+                    'fields': AuthUserAdmin.fieldsets[3][1]['fields'],
+                }),
+            )
         if obj:
             return (
                 AuthUserAdmin.fieldsets[0],  # Note: password is mandatory (but readonly)

+ 1 - 5
adhesions/admin.py

@@ -45,7 +45,7 @@ class AdherentTypeFilter(admin.SimpleListFilter):
 
 
 class AdherentAdmin(admin.ModelAdmin):
-    list_display = ('id', 'adherent_name', 'type',)
+    list_display = ('id', 'name', 'type',)
     list_filter = (AdherentTypeFilter,)
     fields = ('id',)
     readonly_fields = ('id',)
@@ -59,10 +59,6 @@ class AdherentAdmin(admin.ModelAdmin):
 
         return super().get_form(request, obj, **kwargs)
 
-    def adherent_name(self, obj):
-        return str(obj)
-    adherent_name.short_description = 'Nom ou raison sociale'
-
     def has_add_permission(self, request):
         return False
 

+ 8 - 1
adhesions/models.py

@@ -30,11 +30,18 @@ class Adherent(models.Model):
         else:
             return 'Personne morale'
 
-    def __str__(self):
+    def name(self):
         if self.adherent_type.app_label == 'auth' and self.adherent_type.model == 'user':
             return str(self.adherent.profile)
         else:
             return str(self.adherent)
+    name.short_description = 'Nom ou raison sociale'
+
+    def __str__(self):
+        if self.id:
+            return 'Adhérent #%d' % self.id
+        else:
+            return 'Adhérent #?'
 
 
 class AdhesionMixin: