Migr 005[12]: Nehaluzit datum registrace
This commit is contained in:
parent
1de72c09ec
commit
c34dd10995
2 changed files with 8 additions and 1 deletions
|
@ -4,13 +4,15 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.db import migrations
|
||||
|
||||
from datetime import date
|
||||
|
||||
def resitel_to_osoba(apps,schema_editor):
|
||||
Resitel = apps.get_model('seminar','Resitel')
|
||||
Osoba = apps.get_model('seminar','Osoba')
|
||||
for r in Resitel.objects.all():
|
||||
o = Osoba()
|
||||
o.datum_narozeni = r.datum_narozeni
|
||||
o.datum_registrace = r.datum_prihlaseni
|
||||
o.datum_registrace = r.datum_prihlaseni if r.datum_prihlaseni else date.max # Myslím si, že None by způsobilo použití defaultu
|
||||
o.datum_souhlasu_udaje = r.datum_souhlasu_udaje
|
||||
o.datum_souhlasu_zasilani = r.datum_souhlasu_zasilani
|
||||
o.email = r.email
|
||||
|
|
|
@ -4,6 +4,8 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.db import migrations
|
||||
|
||||
from datetime import date
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -23,6 +25,8 @@ def spoj_k_organizatorum_osoby(apps, scema_editor):
|
|||
# Je to podezřelé, ale prostě vyrobíme novou osobu.
|
||||
osoba = Osoba(user=user)
|
||||
# Téhle osobě nejdou nastavit detaily, protože žádné nemáme.
|
||||
# Datum registrace budiž minimální
|
||||
osoba.datum_registrace = date.min
|
||||
else:
|
||||
logger.info(f'Org {org.user.email}(ID: {org.id}) má uživatele {user}')
|
||||
# 💢💢💢 Python nemá goto, ale prý má výjimky… 💢💢💢
|
||||
|
@ -55,6 +59,7 @@ def spoj_k_organizatorum_osoby(apps, scema_editor):
|
|||
osoba.email = user.email
|
||||
user.jmeno += " (Uživatel!)"
|
||||
user.prijmeni += " (Uživatel!)"
|
||||
osoba.datum_registrace = min(osoba.datum_registrace, user.date_joined, key=lambda d: d if d is not None else date.max)
|
||||
user.save()
|
||||
|
||||
except EndException: pass
|
||||
|
|
Loading…
Reference in a new issue