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,)
|
2018-11-22 03:15:21 +00:00
|
|
|
list_display = ('key', 'active', '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-21 23:04:47 +00:00
|
|
|
fieldsets = (
|
|
|
|
(None, {
|
|
|
|
'fields': ('key', 'active')
|
|
|
|
}),
|
|
|
|
('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
|
|
|
|