From 9c1007073de843aa7d26c21b7c31d4e712da631e Mon Sep 17 00:00:00 2001 From: ticvac Date: Sun, 1 Dec 2024 15:44:56 +0100 Subject: [PATCH] try except fix --- mamweb/admin.py | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/mamweb/admin.py b/mamweb/admin.py index 6f79a915..38b1e854 100644 --- a/mamweb/admin.py +++ b/mamweb/admin.py @@ -54,32 +54,11 @@ 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: x['name'].lower()) - app['models'].sort(key=lambda x: ceske_poradi(x['name'])) + try: + for app in app_list: + app['models'].sort(key=lambda x: locale.strxfrm(x['name'].lower())) + except OSError: + pass # locale.strxfrm nefunguje na macu... :-/ -> neprovede se řazení return app_list AdminSite.get_app_list = get_app_list