""" Soubor sloužící k úpravě základních vlastností adminu. Zde se do adminu přidává CKEditor, nastavuje české řazení v adminu a preference (zobrazuje se v seznamu jako první) adminu k Semináři. """ 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! from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld from django.contrib.flatpages.admin import FlatpageForm as FlatpageFormOld from django import forms from django_ckeditor_5.widgets import CKEditor5Widget class FlatpageForm(FlatpageFormOld): content = forms.CharField(widget=CKEditor5Widget()) class Meta: model = FlatPage # this is not automatically inherited from FlatpageFormOld exclude = [] class FlatPageAdmin(FlatPageAdminOld): form = FlatpageForm # We have to unregister the normal admin, and then reregister ours 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, app_label=None): """ Return a sorted list of all the installed apps that have been registered in this site. """ app_dict = self._build_app_dict(request, label=app_label) aplikace_nahore = [ 'tvorba', 'personalni', 'novinky', 'korektury', 'various', 'prednasky', 'soustredeni', ] # 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] # 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