wtf, je to podle dokumentace… a bugreportu
This commit is contained in:
parent
381c5ca3de
commit
bee0083dac
3 changed files with 36 additions and 27 deletions
|
@ -5,7 +5,6 @@ jako první) adminu k Semináři.
|
|||
"""
|
||||
import locale
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin import AdminSite
|
||||
from django.contrib.flatpages.models import FlatPage
|
||||
|
||||
# Note: we are renaming the original Admin and Form as we import them!
|
||||
|
@ -33,15 +32,15 @@ admin.site.register(FlatPage, FlatPageAdmin)
|
|||
|
||||
locale.setlocale(locale.LC_COLLATE, 'cs_CZ.UTF-8')
|
||||
|
||||
# https://books.agiliq.com/projects/django-admin-cookbook/en/latest/set_ordering.html
|
||||
# FIXME zpraseno pomocí toho, že Python umí bez problému přepisovat funkce
|
||||
def get_app_list(self, request, app_label=None):
|
||||
"""
|
||||
Return a sorted list of all the installed apps that have been
|
||||
registered in this site.
|
||||
"""
|
||||
# Ref: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#overriding-default-admin-site
|
||||
# Používá se z mamweb/apps.py
|
||||
class MamwebAdminSite(admin.AdminSite):
|
||||
# Přeuspořádání modelů
|
||||
# Ref: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#django.contrib.admin.AdminSite.get_app_list
|
||||
def get_app_list(self, request, app_label=None):
|
||||
orig_app_list = super().get_app_list(request, app_label)
|
||||
apps_by_label = {app['label']: app for app in orig_app_list}
|
||||
|
||||
app_dict = self._build_app_dict(request, label=app_label)
|
||||
aplikace_nahore = [
|
||||
'seminar',
|
||||
'personalni',
|
||||
|
@ -51,13 +50,10 @@ def get_app_list(self, request, app_label=None):
|
|||
'prednasky',
|
||||
'soustredeni',
|
||||
]
|
||||
app_list = [app_dict[label] for label in aplikace_nahore] + [app_dict[label] for label in app_dict if label not in aplikace_nahore]
|
||||
app_list = [apps_by_label[label] for label in aplikace_nahore] + [apps_by_label[label] for label in apps_by_label if label not in aplikace_nahore]
|
||||
|
||||
|
||||
# Sort the models alphabetically within each app.
|
||||
# TreeNody na konec
|
||||
for app in app_list:
|
||||
app['models'].sort(key=lambda x: locale.strxfrm('žž' + x['name'].lower()) if (x['name'].endswith("(Node)")) else locale.strxfrm(x['name'].lower()))
|
||||
|
||||
return app_list
|
||||
|
||||
AdminSite.get_app_list = get_app_list
|
||||
|
|
12
mamweb/apps.py
Normal file
12
mamweb/apps.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.contrib.admin import apps
|
||||
# Nemůžeme importovat rovnou AdminConfig, jinak se autodetekuje˙:-/
|
||||
# https://code.djangoproject.com/ticket/32642
|
||||
|
||||
# Ref: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#overriding-default-admin-site
|
||||
# Pozn: nad tím je „Customizing the AdminSite class“, ale ta nepřepisuje
|
||||
# default, takže bychom museli přepsat všechny registrace do admina. Proto
|
||||
# radši overridujeme i AdminConfig
|
||||
class MamwebAdminConfig(apps.AdminConfig):
|
||||
default_site = 'mamweb.admin.MamwebAdminSite'
|
||||
|
||||
|
|
@ -108,6 +108,7 @@ INSTALLED_APPS = (
|
|||
'django.contrib.staticfiles',
|
||||
'django.contrib.auth',
|
||||
|
||||
'mamweb.apps',
|
||||
# Utilities
|
||||
'reversion',
|
||||
'django_countries',
|
||||
|
@ -159,7 +160,7 @@ INSTALLED_APPS = (
|
|||
# 'admin_tools.theming',
|
||||
# 'admin_tools.menu',
|
||||
# 'admin_tools.dashboard',
|
||||
'django.contrib.admin',
|
||||
# 'django.contrib.admin',
|
||||
|
||||
# Nechat na konci (INSTALLED_APPS je uspořádané):
|
||||
'django_cleanup.apps.CleanupConfig', # Uklízí media/
|
||||
|
|
Loading…
Reference in a new issue