akce na sjednoceni cisel do +420 123 456 78
This commit is contained in:
parent
c0958d79db
commit
491f91cf47
1 changed files with 19 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue