minecraft_manager/api/admin.py

46 lines
1.5 KiB
Python
Raw Permalink Normal View History

2018-11-21 23:04:47 +00:00
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from minecraft_manager.api.models import Token
class TokenActiveFilter(admin.SimpleListFilter):
title = _('Active')
parameter_name = 'active'
def lookups(self, request, model_admin):
return (
('0', _('Active')),
('1', _('Inactive')),
)
def queryset(self, request, queryset):
if self.value() == '0':
return queryset.filter(active=True)
if self.value() == '1':
return queryset.filter(active=False)
class TokenAdmin(admin.ModelAdmin):
list_filter = (TokenActiveFilter,)
list_display = ('display', 'active', 'web_get_permission', 'web_post_permission', 'plugin_get_permission',
2018-11-22 03:15:21 +00:00
'plugin_post_permission', 'form_get_permission', 'form_post_permission', 'model_get_permission',
'model_post_permission', 'stats_get_permission', 'stats_post_permission')
2018-11-21 23:04:47 +00:00
fieldsets = (
(None, {
2018-11-23 15:30:45 +00:00
'fields': ('key', 'active', 'description')
2018-11-21 23:04:47 +00:00
}),
('Permissions', {
'fields': ('web_get_permission', 'web_post_permission', 'plugin_get_permission', 'plugin_post_permission',
'form_get_permission', 'form_post_permission', 'model_get_permission', 'model_post_permission',
'stats_get_permission', 'stats_post_permission')
})
)
2018-11-22 03:15:21 +00:00
def register():
try:
admin.site.register(Token, TokenAdmin)
except admin.sites.AlreadyRegistered:
pass
2018-11-21 23:04:47 +00:00