Merge pull request #3301 from volundmush/fix_web_admin

Configurable Django Admin
This commit is contained in:
Griatch 2023-10-29 07:35:22 +01:00 committed by GitHub
commit f3a49bb764
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 16 deletions

View file

@ -1033,6 +1033,24 @@ MIDDLEWARE = [
"evennia.web.utils.middleware.SharedLoginMiddleware",
]
# A list of Django apps (see INSTALLED_APPS) that will be listed first (if present)
# in the Django web Admin page.
DJANGO_ADMIN_APP_ORDER = [
"accounts",
"objects",
"scripts",
"comms",
"help",
"typeclasses",
"server",
"sites",
"flatpages",
"auth",
]
# The following apps will be excluded from the Django web Admin page.
DJANGO_ADMIN_APP_EXCLUDE = list()
######################################################################
# Evennia components
######################################################################

View file

@ -8,6 +8,7 @@ of that folder for Django to find them).
"""
from django.conf import settings
from django.contrib import admin
from django.contrib.admin import apps
@ -30,20 +31,11 @@ class EvenniaAdminSite(admin.AdminSite):
site_header = "Evennia web admin"
app_order = [
"accounts",
"objects",
"scripts",
"comms",
"help",
"typeclasses",
"server",
"sites",
"flatpages",
"auth",
]
def get_app_list(self, request):
app_list = super().get_app_list(request)
def get_app_list(self, request, app_label=None):
app_list = super().get_app_list(request, app_label=app_label)
app_mapping = {app["app_label"]: app for app in app_list}
return [app_mapping.get(app_label) for app_label in self.app_order]
out = [app_mapping.pop(app_label) for app_label in settings.DJANGO_ADMIN_APP_ORDER if app_label in app_mapping]
for app in settings.DJANGO_ADMIN_APP_EXCLUDE:
app_mapping.pop(app, None)
out += app_mapping.values()
return out