From c34dd1099517305b505717a0b7a2f7bcd7d01e8e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Tue, 27 Apr 2021 22:00:09 +0200 Subject: [PATCH] Migr 005[12]: Nehaluzit datum registrace --- seminar/migrations/0051_resitel_to_osoba.py | 4 +++- seminar/migrations/0052_user_to_organizator.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/seminar/migrations/0051_resitel_to_osoba.py b/seminar/migrations/0051_resitel_to_osoba.py index 04220896..cba9593b 100644 --- a/seminar/migrations/0051_resitel_to_osoba.py +++ b/seminar/migrations/0051_resitel_to_osoba.py @@ -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 diff --git a/seminar/migrations/0052_user_to_organizator.py b/seminar/migrations/0052_user_to_organizator.py index fec3c2af..8d689a8c 100644 --- a/seminar/migrations/0052_user_to_organizator.py +++ b/seminar/migrations/0052_user_to_organizator.py @@ -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