From 1f77e2a6aa0805f8cd6330c515194d1d39a3cc05 Mon Sep 17 00:00:00 2001 From: ticvac Date: Wed, 27 Nov 2024 11:36:50 +0100 Subject: [PATCH] =?UTF-8?q?hack=20for=20utf-=C3=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mamweb/admin.py | 25 +++++++++++++++++-- .../migrations/0008_alter_rocnik_options.py | 17 +++++++++++++ tvorba/models.py | 4 +-- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 tvorba/migrations/0008_alter_rocnik_options.py diff --git a/mamweb/admin.py b/mamweb/admin.py index a58df505..6f79a915 100644 --- a/mamweb/admin.py +++ b/mamweb/admin.py @@ -54,11 +54,32 @@ def get_app_list(self, request, app_label=None): # Odhlášený admin má prázdný app_dict :-/ app_list = [app_dict[label] for label in aplikace_nahore if label in app_dict] + [app_dict[label] for label in app_dict if label not in aplikace_nahore] + ceska_abeceda = [ + "a", "á", "b", "c", "č", "d", "ď", "e", "é", "ě", "f", "g", + "h", "ch", "i", "í", "j", "k", "l", "m", "n", "ň", "o", "ó", + "p", "q", "r", "ř", "s", "š", "t", "ť", "u", "ú", "ů", "v", + "w", "x", "y", "ý", "z", "ž" + ] + poradi = {znak: index for index, znak in enumerate(ceska_abeceda)} + def ceske_poradi(slovo): + i = 0 + vysledek = [] + slovo = slovo.lower() + while i < len(slovo): + # Zkontroluj, zda aktuální dvojice znaků je "ch" + if i + 1 < len(slovo) and slovo[i:i + 2] == "ch": + vysledek.append(poradi["ch"]) + i += 2 # Přeskoč dva znaky + else: + vysledek.append(poradi.get(slovo[i], -1)) + i += 1 # Přeskoč jeden znak + return vysledek # 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())) + # app['models'].sort(key=lambda x: x['name'].lower()) + app['models'].sort(key=lambda x: ceske_poradi(x['name'])) return app_list AdminSite.get_app_list = get_app_list diff --git a/tvorba/migrations/0008_alter_rocnik_options.py b/tvorba/migrations/0008_alter_rocnik_options.py new file mode 100644 index 00000000..cae24224 --- /dev/null +++ b/tvorba/migrations/0008_alter_rocnik_options.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.16 on 2024-11-26 22:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('tvorba', '0007_alter_deadline_typ'), + ] + + operations = [ + migrations.AlterModelOptions( + name='rocnik', + options={'ordering': ['-rocnik'], 'verbose_name': 'ChRočník', 'verbose_name_plural': 'Ročníky'}, + ), + ] diff --git a/tvorba/models.py b/tvorba/models.py index 36f34312..46fb0057 100644 --- a/tvorba/models.py +++ b/tvorba/models.py @@ -41,8 +41,8 @@ class Rocnik(SeminarModelBase): class Meta: db_table = 'seminar_rocniky' - verbose_name = 'Ročník' - verbose_name_plural = 'Ročníky' + verbose_name = 'ChRočník' + verbose_name_plural = 'ChRočníky' ordering = ['-rocnik'] # Interní ID