From 491f91cf4704170c1bbbe332da796b91b9cd2297 Mon Sep 17 00:00:00 2001 From: ticvac Date: Sat, 15 Jun 2024 22:54:26 +0200 Subject: [PATCH] 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):