forked from Minecraft/minecraft_manager
107 lines
3.0 KiB
Python
107 lines
3.0 KiB
Python
|
from __future__ import absolute_import
|
||
|
|
||
|
from django.contrib import admin
|
||
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||
|
from django.contrib.auth.models import User
|
||
|
from django.utils.translation import ugettext_lazy as _
|
||
|
from minecraft_manager.models import Application, Warning, Ticket, Player, IP, UserSettings, Alert, Note
|
||
|
|
||
|
|
||
|
class PlayerInline(admin.StackedInline):
|
||
|
model = Player
|
||
|
can_delete = False
|
||
|
verbose_name_plural = 'player'
|
||
|
|
||
|
|
||
|
class UserAdmin(BaseUserAdmin):
|
||
|
inlines = (PlayerInline, )
|
||
|
actions = ['deactivate_account']
|
||
|
|
||
|
def deactivate_account(self, request, queryset):
|
||
|
rows_updated = queryset.update(is_active=False)
|
||
|
if rows_updated == 1:
|
||
|
message_bit = "1 user was"
|
||
|
else:
|
||
|
message_bit = "%s users were" % rows_updated
|
||
|
self.message_user(request, "%s successfully deactivated." % message_bit)
|
||
|
deactivate_account.short_description = "Deactivate selected accounts"
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
class PlayerAdmin(admin.ModelAdmin):
|
||
|
search_fields = ["username", "uuid"]
|
||
|
|
||
|
|
||
|
class ApplicationAdmin(admin.ModelAdmin):
|
||
|
search_fields = ["username"]
|
||
|
#date_hierarchy = 'date'
|
||
|
|
||
|
|
||
|
class TicketPriorityFilter(admin.SimpleListFilter):
|
||
|
title = _('Priority')
|
||
|
parameter_name = 'priority'
|
||
|
|
||
|
def lookups(self, request, model_admin):
|
||
|
return (
|
||
|
('0', _('Low')),
|
||
|
('1', _('Medium')),
|
||
|
('2', _('High'))
|
||
|
)
|
||
|
|
||
|
def queryset(self, request, queryset):
|
||
|
if self.value() == '0':
|
||
|
return queryset.filter(priority='L')
|
||
|
if self.value() == '1':
|
||
|
return queryset.filter(priority='M')
|
||
|
if self.value() == '2':
|
||
|
return queryset.filter(priority='H')
|
||
|
|
||
|
|
||
|
class TicketAdmin(admin.ModelAdmin):
|
||
|
search_fields = ["player__username", "staff__username"]
|
||
|
#date_hierarchy = 'date'
|
||
|
list_filter = (TicketPriorityFilter,)
|
||
|
|
||
|
|
||
|
class WarningSeverityFilter(admin.SimpleListFilter):
|
||
|
title = _('Severity')
|
||
|
parameter_name = 'severity'
|
||
|
|
||
|
def lookups(self, request, model_admin):
|
||
|
return (
|
||
|
('0', _('Low')),
|
||
|
('1', _('Medium')),
|
||
|
('2', _('High'))
|
||
|
)
|
||
|
|
||
|
def queryset(self, request, queryset):
|
||
|
if self.value() == '0':
|
||
|
return queryset.filter(priority='L')
|
||
|
if self.value() == '1':
|
||
|
return queryset.filter(priority='M')
|
||
|
if self.value() == '2':
|
||
|
return queryset.filter(priority='H')
|
||
|
|
||
|
|
||
|
class WarningAdmin(admin.ModelAdmin):
|
||
|
search_fields = ["player__username", "staff__username"]
|
||
|
#date_hierarchy = 'date'
|
||
|
list_filter = (WarningSeverityFilter,)
|
||
|
|
||
|
|
||
|
try:
|
||
|
admin.site.unregister(User)
|
||
|
admin.site.register(User, UserAdmin)
|
||
|
admin.site.register(UserSettings)
|
||
|
admin.site.register(Application, ApplicationAdmin)
|
||
|
admin.site.register(Warning, WarningAdmin)
|
||
|
admin.site.register(Ticket, TicketAdmin)
|
||
|
admin.site.register(Player, PlayerAdmin)
|
||
|
admin.site.register(IP)
|
||
|
admin.site.register(Alert)
|
||
|
admin.site.register(Note)
|
||
|
except admin.sites.AlreadyRegistered:
|
||
|
pass
|
||
|
|