mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Admin UI improvements
This commit is contained in:
@ -35,20 +35,42 @@ class UserConfigInline(admin.TabularInline):
|
|||||||
verbose_name = 'Preferences'
|
verbose_name = 'Preferences'
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectPermissionInline(admin.TabularInline):
|
||||||
|
model = AdminUser.object_permissions.through
|
||||||
|
fields = ['content_types', 'actions', 'attrs']
|
||||||
|
readonly_fields = fields
|
||||||
|
extra = 0
|
||||||
|
verbose_name = 'Permission'
|
||||||
|
|
||||||
|
def content_types(self, instance):
|
||||||
|
return ', '.join(instance.objectpermission.content_types.values_list('model', flat=True))
|
||||||
|
|
||||||
|
def actions(self, instance):
|
||||||
|
return ', '.join(instance.objectpermission.actions)
|
||||||
|
|
||||||
|
def attrs(self, instance):
|
||||||
|
return instance.objectpermission.attrs
|
||||||
|
|
||||||
|
def has_add_permission(self, request, obj):
|
||||||
|
# Don't allow the creation of new ObjectPermission assignments via this form
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@admin.register(AdminUser)
|
@admin.register(AdminUser)
|
||||||
class UserAdmin(UserAdmin_):
|
class UserAdmin(UserAdmin_):
|
||||||
list_display = [
|
list_display = [
|
||||||
'username', 'email', 'first_name', 'last_name', 'is_superuser', 'is_staff', 'is_active'
|
'username', 'email', 'first_name', 'last_name', 'is_superuser', 'is_staff', 'is_active'
|
||||||
]
|
]
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {'fields': ('username', 'password')}),
|
(None, {'fields': ('username', 'password', 'first_name', 'last_name', 'email')}),
|
||||||
('Personal info', {'fields': ('first_name', 'last_name', 'email')}),
|
('Groups', {'fields': ('groups',)}),
|
||||||
('Permissions', {
|
('Permissions', {
|
||||||
'fields': ('is_active', 'is_staff', 'is_superuser'),
|
'fields': ('is_active', 'is_staff', 'is_superuser'),
|
||||||
}),
|
}),
|
||||||
('Important dates', {'fields': ('last_login', 'date_joined')}),
|
('Important dates', {'fields': ('last_login', 'date_joined')}),
|
||||||
)
|
)
|
||||||
inlines = (UserConfigInline,)
|
inlines = [ObjectPermissionInline, UserConfigInline]
|
||||||
|
filter_horizontal = ('groups',)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -154,7 +176,7 @@ class ObjectPermissionAdmin(admin.ModelAdmin):
|
|||||||
'fields': ('content_types',)
|
'fields': ('content_types',)
|
||||||
}),
|
}),
|
||||||
('Assignment', {
|
('Assignment', {
|
||||||
'fields': (('groups', 'users'),)
|
'fields': ('groups', 'users')
|
||||||
}),
|
}),
|
||||||
('Actions', {
|
('Actions', {
|
||||||
'fields': (('can_view', 'can_add', 'can_change', 'can_delete'), 'actions')
|
'fields': (('can_view', 'can_add', 'can_change', 'can_delete'), 'actions')
|
||||||
@ -163,10 +185,14 @@ class ObjectPermissionAdmin(admin.ModelAdmin):
|
|||||||
'fields': ('attrs',)
|
'fields': ('attrs',)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
filter_horizontal = ('content_types', 'groups', 'users')
|
||||||
form = ObjectPermissionForm
|
form = ObjectPermissionForm
|
||||||
list_display = [
|
list_display = [
|
||||||
'list_models', 'list_users', 'list_groups', 'actions', 'attrs',
|
'list_models', 'list_users', 'list_groups', 'actions', 'attrs',
|
||||||
]
|
]
|
||||||
|
list_filter = [
|
||||||
|
'groups', 'users'
|
||||||
|
]
|
||||||
|
|
||||||
def get_queryset(self, request):
|
def get_queryset(self, request):
|
||||||
return super().get_queryset(request).prefetch_related('content_types', 'users', 'groups')
|
return super().get_queryset(request).prefetch_related('content_types', 'users', 'groups')
|
||||||
|
@ -21,6 +21,7 @@ class Migration(migrations.Migration):
|
|||||||
'proxy': True,
|
'proxy': True,
|
||||||
'indexes': [],
|
'indexes': [],
|
||||||
'constraints': [],
|
'constraints': [],
|
||||||
|
'verbose_name': 'Group',
|
||||||
},
|
},
|
||||||
bases=('auth.group',),
|
bases=('auth.group',),
|
||||||
managers=[
|
managers=[
|
||||||
@ -35,6 +36,7 @@ class Migration(migrations.Migration):
|
|||||||
'proxy': True,
|
'proxy': True,
|
||||||
'indexes': [],
|
'indexes': [],
|
||||||
'constraints': [],
|
'constraints': [],
|
||||||
|
'verbose_name': 'User',
|
||||||
},
|
},
|
||||||
bases=('auth.user',),
|
bases=('auth.user',),
|
||||||
managers=[
|
managers=[
|
||||||
|
@ -29,6 +29,7 @@ class AdminGroup(Group):
|
|||||||
Proxy contrib.auth.models.Group for the admin UI
|
Proxy contrib.auth.models.Group for the admin UI
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
|
verbose_name = 'Group'
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ class AdminUser(User):
|
|||||||
Proxy contrib.auth.models.User for the admin UI
|
Proxy contrib.auth.models.User for the admin UI
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
|
verbose_name = 'User'
|
||||||
proxy = True
|
proxy = True
|
||||||
|
|
||||||
|
|
||||||
@ -264,4 +266,7 @@ class ObjectPermission(models.Model):
|
|||||||
verbose_name = "Permission"
|
verbose_name = "Permission"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Object permission"
|
return '{}: {}'.format(
|
||||||
|
', '.join(self.content_types.values_list('model', flat=True)),
|
||||||
|
', '.join(self.actions)
|
||||||
|
)
|
||||||
|
Reference in New Issue
Block a user