From 8dbb92d3a4e779121c56bfca5d35117ce0a4cc1e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 2 Jun 2024 17:17:57 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Filtrov=C3=A1ni=20=C5=99e=C5=A1itel=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- personalni/admin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/personalni/admin.py b/personalni/admin.py index 14af2c2c..b3506fc4 100644 --- a/personalni/admin.py +++ b/personalni/admin.py @@ -53,6 +53,7 @@ class OrganizatorAdmin(ReverseModelAdmin): @admin.register(m.Resitel) class ResitelAdmin(ReverseModelAdmin): search_fields = ['osoba__jmeno', 'osoba__prijmeni', 'osoba__prezdivka'] + list_filter = ['zasilat', 'zasilat_cislo_papirove', 'zasilat_cislo_emailem', 'rok_maturity'] ordering = ('osoba__prijmeni', 'osoba__jmeno') inline_type = 'stacked' inline_reverse = ['osoba'] From e431e23ad42467abd9b82c0bef713eea4cb3ab53 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 2 Jun 2024 18:08:18 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Vyr=C3=A1b=C4=9Bn=C3=AD=20org=C5=AF=20z=20?= =?UTF-8?q?=C5=99e=C5=A1itel=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- personalni/admin.py | 50 +++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/personalni/admin.py b/personalni/admin.py index b3506fc4..81cf7ecb 100644 --- a/personalni/admin.py +++ b/personalni/admin.py @@ -5,10 +5,31 @@ from django.contrib.messages import WARNING, ERROR, SUCCESS import seminar.models as m from datetime import datetime +# Tohle chceme umět použít i z ResitelAdmin +@admin.action(description="Udělej z vybraných osob organizátory") +def udelej_orgem(admin, request, queryset): + org_group = Group.objects.get(name='org') + uspesne_vytvoreni_orgove = 0 + for o in queryset: + if m.Organizator.objects.filter(osoba=o).exists(): + # Ref: https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.message_user + admin.message_user(request, f"Osoba {o} už je org, přeskakuji.", level=WARNING) + continue + user = o.user + if user is None: + admin.message_user(request, f"Osoba {o} nemá uživatele! Přeskakuji.", level=ERROR) + continue + user.groups.add(org_group) + user.is_staff = True + user.save() + org = m.Organizator.objects.create(osoba=o, organizuje_od=datetime.now()) + org.save() + uspesne_vytvoreni_orgove += 1 + admin.message_user(request, f'Úspěšně vytvořeno {uspesne_vytvoreni_orgove} orgů.', level=SUCCESS) @admin.register(m.Osoba) class OsobaAdmin(admin.ModelAdmin): - actions = ['synchronizuj_maily', 'udelej_orgem'] + actions = ['synchronizuj_maily', udelej_orgem] search_fields = ['jmeno', 'prijmeni', 'prezdivka'] def synchronizuj_maily(self, request, queryset): @@ -20,27 +41,6 @@ class OsobaAdmin(admin.ModelAdmin): self.message_user(request, "E-maily synchronizovány.") synchronizuj_maily.short_description = "Synchronizuj vybraným osobám e-maily do uživatelů" - def udelej_orgem(self,request,queryset): - org_group = Group.objects.get(name='org') - uspesne_vytvoreni_orgove = 0 - for o in queryset: - if m.Organizator.objects.filter(osoba=o).exists(): - # Ref: https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.message_user - self.message_user(request, f"Osoba {o} už je org, přeskakuji.", level=WARNING) - continue - user = o.user - if user is None: - self.message_user(request, f"Osoba {o} nemá uživatele! Přeskakuji.", level=ERROR) - continue - user.groups.add(org_group) - user.is_staff = True - user.save() - org = m.Organizator.objects.create(osoba=o, organizuje_od=datetime.now()) - org.save() - uspesne_vytvoreni_orgove += 1 - self.message_user(request, f'Úspěšně vytvořeno {uspesne_vytvoreni_orgove} orgů.', level=SUCCESS) - udelej_orgem.short_description = "Udělej z vybraných osob organizátory" - class OsobaInline(admin.TabularInline): model = m.Osoba @@ -58,5 +58,11 @@ class ResitelAdmin(ReverseModelAdmin): inline_type = 'stacked' inline_reverse = ['osoba'] + actions = ['udelej_resitele_orgem'] + @admin.action(description="Udělej z řešitelů organizátory") + def udelej_resitele_orgem(self, req, qs): + osoby = m.Osoba.objects.filter(resitel__in=qs) + udelej_orgem(self, req, osoby) + admin.site.register(m.Skola) admin.site.register(m.Prijemce)