From e86c090ab849faa0a64548a3dbd37168ab2dbb49 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Thu, 16 Jan 2020 01:26:08 +0100 Subject: [PATCH] =?UTF-8?q?Admin:=20Akce=20na=20synchronizaci=20duplicit?= =?UTF-8?q?=20informac=C3=AD=20v=20datab=C3=A1zi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/admin.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/seminar/admin.py b/seminar/admin.py index 11944b56..6a9dd815 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -8,7 +8,6 @@ from django_reverse_admin import ReverseModelAdmin import seminar.models as m -admin.site.register(m.Osoba) admin.site.register(m.Skola) admin.site.register(m.Prijemce) admin.site.register(m.Rocnik) @@ -16,6 +15,19 @@ admin.site.register(m.Cislo) admin.site.register(m.Organizator) admin.site.register(m.Soustredeni) +@admin.register(m.Osoba) +class OsobaAdmin(admin.ModelAdmin): + actions = ['synchronizuj_maily'] + + def synchronizuj_maily(self, request, queryset): + for o in queryset: + if o.user is not None: + u = o.user + u.email = o.email + u.save() + self.message_user(request, "E-maily synchronizovány.") + synchronizuj_maily.short_description = "Synchronizuj vybraným osobám e-maily do uživatelů" + @admin.register(m.Problem) class ProblemAdmin(PolymorphicParentModelAdmin): base_model = m.Problem @@ -93,6 +105,17 @@ class TreeNodeAdmin(PolymorphicParentModelAdmin): m.TextNode, ] + actions = ['aktualizuj_nazvy'] + + # XXX: nejspíš je to totální DB HOG, nechcete to použít moc často. + def aktualizuj_nazvy(self, request, queryset): + newqs = queryset.get_real_instances() + for tn in newqs: + tn.aktualizuj_nazev() + tn.save() + self.message_user(request, "Názvy aktualizovány.") + aktualizuj_nazvy.short_description = "Aktualizuj vybraným TreeNodům názvy" + @admin.register(m.RocnikNode) class RocnikNodeAdmin(PolymorphicChildModelAdmin): base_model = m.RocnikNode