Compare commits

...

1 Commits

Author SHA1 Message Date
Pavel "LEdoian" Turinsky bee0083dac wtf, je to podle dokumentace… a bugreportu 6 months ago
  1. 54
      mamweb/admin.py
  2. 12
      mamweb/apps.py
  3. 3
      mamweb/settings_common.py

54
mamweb/admin.py

@ -5,7 +5,6 @@ jako první) adminu k Semináři.
""" """
import locale import locale
from django.contrib import admin from django.contrib import admin
from django.contrib.admin import AdminSite
from django.contrib.flatpages.models import FlatPage from django.contrib.flatpages.models import FlatPage
# Note: we are renaming the original Admin and Form as we import them! # Note: we are renaming the original Admin and Form as we import them!
@ -33,31 +32,28 @@ admin.site.register(FlatPage, FlatPageAdmin)
locale.setlocale(locale.LC_COLLATE, 'cs_CZ.UTF-8') locale.setlocale(locale.LC_COLLATE, 'cs_CZ.UTF-8')
# https://books.agiliq.com/projects/django-admin-cookbook/en/latest/set_ordering.html # Ref: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#overriding-default-admin-site
# FIXME zpraseno pomocí toho, že Python umí bez problému přepisovat funkce # Používá se z mamweb/apps.py
def get_app_list(self, request, app_label=None): class MamwebAdminSite(admin.AdminSite):
""" # Přeuspořádání modelů
Return a sorted list of all the installed apps that have been # Ref: https://docs.djangoproject.com/en/4.2/ref/contrib/admin/#django.contrib.admin.AdminSite.get_app_list
registered in this site. 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 = [ aplikace_nahore = [
'seminar', 'seminar',
'personalni', 'personalni',
'novinky', 'novinky',
'korektury', 'korektury',
'various', 'various',
'prednasky', 'prednasky',
'soustredeni', '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]
# TreeNody na konec
# Sort the models alphabetically within each app. for app in app_list:
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()))
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
return app_list
AdminSite.get_app_list = get_app_list

12
mamweb/apps.py

@ -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'

3
mamweb/settings_common.py

@ -108,6 +108,7 @@ INSTALLED_APPS = (
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.auth', 'django.contrib.auth',
'mamweb.apps',
# Utilities # Utilities
'reversion', 'reversion',
'django_countries', 'django_countries',
@ -159,7 +160,7 @@ INSTALLED_APPS = (
# 'admin_tools.theming', # 'admin_tools.theming',
# 'admin_tools.menu', # 'admin_tools.menu',
# 'admin_tools.dashboard', # 'admin_tools.dashboard',
'django.contrib.admin', # 'django.contrib.admin',
# Nechat na konci (INSTALLED_APPS je uspořádané): # Nechat na konci (INSTALLED_APPS je uspořádané):
'django_cleanup.apps.CleanupConfig', # Uklízí media/ 'django_cleanup.apps.CleanupConfig', # Uklízí media/

Loading…
Cancel
Save