minecraft_manager/admin.py

117 lines
3.4 KiB
Python
Raw Permalink Normal View History

2018-09-20 02:56:17 +00:00
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 _
attachments (#2) Add migration for longer timezone Signed-off-by: Etzelia <etzelia@hotmail.com> Merge branch 'master' of birbmc.com:BirbMC/minecraft_manager into birb # Conflicts: # external/views.py Fix col Signed-off-by: Etzelia <etzelia@hotmail.com> Add attachments, clean up UI, etc. Signed-off-by: Etzelia <etzelia@hotmail.com> Fix Discord embeds (#59) Fix Discord embeds Reviewed-on: https://git.etztech.xyz/MMS/MinecraftManagerDjango/pulls/59 Reviewed-by: ZeroHD <joey@ahines.net> Add requirements (not txt) (#57) Add requirements (not txt) Signed-off-by: Etzelia <etzelia@hotmail.com> Reviewed-on: https://git.etztech.xyz/MMS/MinecraftManagerDjango/pulls/57 Reviewed-by: ZeroHD <joey@ahines.net> Interim Patch (#54) Birb Patches (#1) Birb Patches Signed-off-by: Etzelia <etzelia@hotmail.com> Co-authored-by: Etzelia <etzelia@hotmail.com> Reviewed-by: ZeroHD <joey@ahines.net> Add 'LICENSE' (#53) Add 'LICENSE' Reviewed-by: ZeroHD <joey@ahines.net> Fix captcha and generify community invite (#52) Add validation for final question and some minor CSS Signed-off-by: Etzelia <etzelia@hotmail.com> Change some docs Signed-off-by: Etzelia <etzelia@hotmail.com> Fix captcha and generify community invite Signed-off-by: Etzelia <etzelia@hotmail.com> Co-authored-by: Etzelia <etzelia@hotmail.com> Reviewed-by: ZeroHD <joey@ahines.net> Co-authored-by: Etz Elia <etzelia@hotmail.com> Reviewed-on: https://git.birbmc.com/BirbMC/minecraft_manager/pulls/2 Co-Authored-By: Etzelia <etzelia@hotmail.com> Co-Committed-By: Etzelia <etzelia@hotmail.com>
2021-05-06 17:50:18 +00:00
from minecraft_manager.models import Application, Note, Ticket, TicketNote, Player, IP, UserSettings, Alert, Attachment
2018-11-22 03:15:21 +00:00
from minecraft_manager.api.admin import register as api_register
2018-09-20 02:56:17 +00:00
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"]
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"]
list_filter = (TicketPriorityFilter,)
class NoteImportanceFilter(admin.SimpleListFilter):
title = _('Importance')
parameter_name = 'importance'
2018-09-20 02:56:17 +00:00
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 NoteAdmin(admin.ModelAdmin):
2018-09-20 02:56:17 +00:00
search_fields = ["player__username", "staff__username"]
list_filter = (NoteImportanceFilter,)
2018-09-20 02:56:17 +00:00
class IPAdmin(admin.ModelAdmin):
search_fields = ["player__username", "ip"]
attachments (#2) Add migration for longer timezone Signed-off-by: Etzelia <etzelia@hotmail.com> Merge branch 'master' of birbmc.com:BirbMC/minecraft_manager into birb # Conflicts: # external/views.py Fix col Signed-off-by: Etzelia <etzelia@hotmail.com> Add attachments, clean up UI, etc. Signed-off-by: Etzelia <etzelia@hotmail.com> Fix Discord embeds (#59) Fix Discord embeds Reviewed-on: https://git.etztech.xyz/MMS/MinecraftManagerDjango/pulls/59 Reviewed-by: ZeroHD <joey@ahines.net> Add requirements (not txt) (#57) Add requirements (not txt) Signed-off-by: Etzelia <etzelia@hotmail.com> Reviewed-on: https://git.etztech.xyz/MMS/MinecraftManagerDjango/pulls/57 Reviewed-by: ZeroHD <joey@ahines.net> Interim Patch (#54) Birb Patches (#1) Birb Patches Signed-off-by: Etzelia <etzelia@hotmail.com> Co-authored-by: Etzelia <etzelia@hotmail.com> Reviewed-by: ZeroHD <joey@ahines.net> Add 'LICENSE' (#53) Add 'LICENSE' Reviewed-by: ZeroHD <joey@ahines.net> Fix captcha and generify community invite (#52) Add validation for final question and some minor CSS Signed-off-by: Etzelia <etzelia@hotmail.com> Change some docs Signed-off-by: Etzelia <etzelia@hotmail.com> Fix captcha and generify community invite Signed-off-by: Etzelia <etzelia@hotmail.com> Co-authored-by: Etzelia <etzelia@hotmail.com> Reviewed-by: ZeroHD <joey@ahines.net> Co-authored-by: Etz Elia <etzelia@hotmail.com> Reviewed-on: https://git.birbmc.com/BirbMC/minecraft_manager/pulls/2 Co-Authored-By: Etzelia <etzelia@hotmail.com> Co-Committed-By: Etzelia <etzelia@hotmail.com>
2021-05-06 17:50:18 +00:00
class AttachmentAdmin(admin.ModelAdmin):
list_display = ["file_name", "model_name"]
def model_name(self, attachment):
return attachment.ref_name
model_name.short_description = "Model"
2018-09-20 02:56:17 +00:00
try:
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
admin.site.register(UserSettings)
admin.site.register(Application, ApplicationAdmin)
admin.site.register(Ticket, TicketAdmin)
admin.site.register(TicketNote)
admin.site.register(Note, NoteAdmin)
2018-09-20 02:56:17 +00:00
admin.site.register(Player, PlayerAdmin)
admin.site.register(IP, IPAdmin)
2018-09-20 02:56:17 +00:00
admin.site.register(Alert)
attachments (#2) Add migration for longer timezone Signed-off-by: Etzelia <etzelia@hotmail.com> Merge branch 'master' of birbmc.com:BirbMC/minecraft_manager into birb # Conflicts: # external/views.py Fix col Signed-off-by: Etzelia <etzelia@hotmail.com> Add attachments, clean up UI, etc. Signed-off-by: Etzelia <etzelia@hotmail.com> Fix Discord embeds (#59) Fix Discord embeds Reviewed-on: https://git.etztech.xyz/MMS/MinecraftManagerDjango/pulls/59 Reviewed-by: ZeroHD <joey@ahines.net> Add requirements (not txt) (#57) Add requirements (not txt) Signed-off-by: Etzelia <etzelia@hotmail.com> Reviewed-on: https://git.etztech.xyz/MMS/MinecraftManagerDjango/pulls/57 Reviewed-by: ZeroHD <joey@ahines.net> Interim Patch (#54) Birb Patches (#1) Birb Patches Signed-off-by: Etzelia <etzelia@hotmail.com> Co-authored-by: Etzelia <etzelia@hotmail.com> Reviewed-by: ZeroHD <joey@ahines.net> Add 'LICENSE' (#53) Add 'LICENSE' Reviewed-by: ZeroHD <joey@ahines.net> Fix captcha and generify community invite (#52) Add validation for final question and some minor CSS Signed-off-by: Etzelia <etzelia@hotmail.com> Change some docs Signed-off-by: Etzelia <etzelia@hotmail.com> Fix captcha and generify community invite Signed-off-by: Etzelia <etzelia@hotmail.com> Co-authored-by: Etzelia <etzelia@hotmail.com> Reviewed-by: ZeroHD <joey@ahines.net> Co-authored-by: Etz Elia <etzelia@hotmail.com> Reviewed-on: https://git.birbmc.com/BirbMC/minecraft_manager/pulls/2 Co-Authored-By: Etzelia <etzelia@hotmail.com> Co-Committed-By: Etzelia <etzelia@hotmail.com>
2021-05-06 17:50:18 +00:00
admin.site.register(Attachment, AttachmentAdmin)
2018-11-22 03:15:21 +00:00
api_register()
2018-09-20 02:56:17 +00:00
except admin.sites.AlreadyRegistered:
pass