From 491f91cf4704170c1bbbe332da796b91b9cd2297 Mon Sep 17 00:00:00 2001 From: ticvac Date: Sat, 15 Jun 2024 22:54:26 +0200 Subject: [PATCH 1/3] akce na sjednoceni cisel do +420 123 456 78 --- personalni/admin.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/personalni/admin.py b/personalni/admin.py index 81cf7ecb..ecb59674 100644 --- a/personalni/admin.py +++ b/personalni/admin.py @@ -5,6 +5,24 @@ from django.contrib.messages import WARNING, ERROR, SUCCESS import seminar.models as m from datetime import datetime +@admin.action(description="Sjednoť telefony") +def sjednot_telefony(admin, request, queryset): + for o in queryset: + try: + telefon = int(o.telefon.replace(" ", "").replace("+", "")) + # 6 míst + if len(str(telefon)) == 9: + o.telefon = "+420 " + str(telefon)[0:3] + " " + str(telefon)[3:6] + " " + str(telefon)[6:9] + o.save() + # 12 míst + elif len(str(telefon)) == 12: + o.telefon = "+" + str(telefon)[0:3] + " " + str(telefon)[3:6] + " " + str(telefon)[6:9] + " " + str(telefon)[9:12] + o.save() + else: + raise ValueError + except: + print("Hmm má divné číslo - " + o.telefon + " - " + str(o.id)) + # 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): @@ -29,7 +47,7 @@ def udelej_orgem(admin, request, queryset): @admin.register(m.Osoba) class OsobaAdmin(admin.ModelAdmin): - actions = ['synchronizuj_maily', udelej_orgem] + actions = ['synchronizuj_maily', udelej_orgem, sjednot_telefony] search_fields = ['jmeno', 'prijmeni', 'prezdivka'] def synchronizuj_maily(self, request, queryset): -- 2.39.5 From fad2c6940d6a2b755702d457753b8faa746a54e3 Mon Sep 17 00:00:00 2001 From: ticvac Date: Sat, 15 Jun 2024 23:20:35 +0200 Subject: [PATCH 2/3] =?UTF-8?q?oprava=20chybov=C3=A9=20hl=C3=A1=C5=A1ky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- personalni/admin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/personalni/admin.py b/personalni/admin.py index ecb59674..e86898db 100644 --- a/personalni/admin.py +++ b/personalni/admin.py @@ -21,7 +21,8 @@ def sjednot_telefony(admin, request, queryset): else: raise ValueError except: - print("Hmm má divné číslo - " + o.telefon + " - " + str(o.id)) + admin.message_user(request, f"{o.jmeno} {o.prijmeni} (id: {o.id}) má divný telefon: {o.telefon}", level=ERROR) + admin.message_user(request, "Telefony sjednoceny.", level=SUCCESS) # Tohle chceme umět použít i z ResitelAdmin @admin.action(description="Udělej z vybraných osob organizátory") -- 2.39.5 From cf3c9f6f805dc839f6550bbae74b5abba67bb82c Mon Sep 17 00:00:00 2001 From: ticvac Date: Sat, 15 Jun 2024 23:27:42 +0200 Subject: [PATCH 3/3] prazdy string -> continue --- personalni/admin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/personalni/admin.py b/personalni/admin.py index e86898db..3418769a 100644 --- a/personalni/admin.py +++ b/personalni/admin.py @@ -8,6 +8,8 @@ from datetime import datetime @admin.action(description="Sjednoť telefony") def sjednot_telefony(admin, request, queryset): for o in queryset: + if o.telefon == '': + continue try: telefon = int(o.telefon.replace(" ", "").replace("+", "")) # 6 míst -- 2.39.5