Merge branch 'master' into clanek-strana
This commit is contained in:
commit
0bebee5329
1 changed files with 22 additions and 1 deletions
|
@ -5,6 +5,27 @@ 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:
|
||||
if o.telefon == '':
|
||||
continue
|
||||
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:
|
||||
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")
|
||||
def udelej_orgem(admin, request, queryset):
|
||||
|
@ -29,7 +50,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