From e90cc4e6b3ec7cfc54de8ef80e4f94753dc313fd Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Thu, 16 Sep 2021 18:31:20 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Fix=20=C5=99azen=C3=AD=20v=C4=9Bc=C3=AD=20n?= =?UTF-8?q?a=20hlavn=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 From adc0c6897702e9fb54dcf564b7023ca13b1f9862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Tue, 16 Nov 2021 10:14:16 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Fix=20=C5=99adit=20(Node)=20jako=20posledn?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mamweb/admin.py b/mamweb/admin.py index aa93d11a..9c421309 100644 --- a/mamweb/admin.py +++ b/mamweb/admin.py @@ -38,11 +38,11 @@ def get_app_list(self, request): 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())) + app_list = sorted(app_dict.values(), key=lambda x: locale.strxfrm('!') 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())) + 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