From e90cc4e6b3ec7cfc54de8ef80e4f94753dc313fd Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Thu, 16 Sep 2021 18:31:20 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20=C5=99azen=C3=AD=20v=C4=9Bc=C3=AD=20na=20?= =?UTF-8?q?hlavn=C3=AD=20str=C3=A1nce=20adminu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/admin.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mamweb/admin.py b/mamweb/admin.py index 12d063f7..aa93d11a 100644 --- a/mamweb/admin.py +++ b/mamweb/admin.py @@ -1,4 +1,6 @@ +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! @@ -24,3 +26,24 @@ class FlatPageAdmin(FlatPageAdminOld): admin.site.unregister(FlatPage) 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): + """ + Return a sorted list of all the installed apps that have been + registered in this site. + """ + + app_dict = self._build_app_dict(request) + # Sort the apps alphabetically. + app_list = sorted(app_dict.values(), key=lambda x: locale.strxfrm('0') if (x['name'] == "Seminar") else locale.strxfrm(x['name'].lower())) + + # Sort the models alphabetically within each app. + for app in app_list: + app['models'].sort(key=lambda x: locale.strxfrm(x['name'].lower())) + + return app_list + +AdminSite.get_app_list = get_app_list