Merge branch 'data_migrations' of gimli.ms.mff.cuni.cz:/akce/mam/git/mamweb into data_migrations
This commit is contained in:
commit
26e6f601aa
2 changed files with 8 additions and 1 deletions
|
@ -4,13 +4,15 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
def resitel_to_osoba(apps,schema_editor):
|
def resitel_to_osoba(apps,schema_editor):
|
||||||
Resitel = apps.get_model('seminar','Resitel')
|
Resitel = apps.get_model('seminar','Resitel')
|
||||||
Osoba = apps.get_model('seminar','Osoba')
|
Osoba = apps.get_model('seminar','Osoba')
|
||||||
for r in Resitel.objects.all():
|
for r in Resitel.objects.all():
|
||||||
o = Osoba()
|
o = Osoba()
|
||||||
o.datum_narozeni = r.datum_narozeni
|
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_udaje = r.datum_souhlasu_udaje
|
||||||
o.datum_souhlasu_zasilani = r.datum_souhlasu_zasilani
|
o.datum_souhlasu_zasilani = r.datum_souhlasu_zasilani
|
||||||
o.email = r.email
|
o.email = r.email
|
||||||
|
|
|
@ -4,6 +4,8 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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.
|
# Je to podezřelé, ale prostě vyrobíme novou osobu.
|
||||||
osoba = Osoba(user=user)
|
osoba = Osoba(user=user)
|
||||||
# Téhle osobě nejdou nastavit detaily, protože žádné nemáme.
|
# Téhle osobě nejdou nastavit detaily, protože žádné nemáme.
|
||||||
|
# Datum registrace budiž minimální
|
||||||
|
osoba.datum_registrace = date.min
|
||||||
else:
|
else:
|
||||||
logger.info(f'Org {org.user.email}(ID: {org.id}) má uživatele {user}')
|
logger.info(f'Org {org.user.email}(ID: {org.id}) má uživatele {user}')
|
||||||
# 💢💢💢 Python nemá goto, ale prý má výjimky… 💢💢💢
|
# 💢💢💢 Python nemá goto, ale prý má výjimky… 💢💢💢
|
||||||
|
@ -55,6 +59,7 @@ def spoj_k_organizatorum_osoby(apps, scema_editor):
|
||||||
osoba.email = user.email
|
osoba.email = user.email
|
||||||
user.jmeno += " (Uživatel!)"
|
user.jmeno += " (Uživatel!)"
|
||||||
user.prijmeni += " (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()
|
user.save()
|
||||||
|
|
||||||
except EndException: pass
|
except EndException: pass
|
||||||
|
|
Loading…
Reference in a new issue