From 8dceaec349b684c6a131fcd734ae0f2bd875f34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Tue, 11 Oct 2022 11:00:53 +0200 Subject: [PATCH] =?UTF-8?q?Migrace=20zachov=C3=A1vaj=C3=ADc=C3=AD=20v?= =?UTF-8?q?=C3=BDsledkovky=20ro=C4=8Dn=C3=ADku=20<=2026?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/migrations/0103_deadline.py | 26 +++++++++---------- .../0104_hodnoceni_deadline_body.py | 6 +++++ seminar/models/odevzdavatko.py | 1 + seminar/models/tvorba.py | 1 + 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/seminar/migrations/0103_deadline.py b/seminar/migrations/0103_deadline.py index 406c7200..5ace15b9 100644 --- a/seminar/migrations/0103_deadline.py +++ b/seminar/migrations/0103_deadline.py @@ -12,25 +12,23 @@ import seminar.models as m def vytvor_deadliny(apps, schema_editor): Cislo = apps.get_model('seminar', 'Cislo') Deadline = apps.get_model('seminar', 'Deadline') - Hodnoceni = apps.get_model('seminar', 'Hodnoceni') for cislo in Cislo.objects.all(): - if not (cislo.datum_deadline or cislo.datum_deadline_soustredeni or cislo.datum_preddeadline): - h = Hodnoceni.objects.filter(problem__uloha__cislo_zadani=cislo).order_by(F("reseni__cas_doruceni")).last() - - if h is None: - h = Hodnoceni.objects.filter(cislo_body=cislo).order_by(F("reseni__cas_doruceni")).last() - - if h is not None: - cislo.datum_deadline = h.reseni.cas_doruceni.date() - cislo.save() + if cislo.rocnik.rocnik < 26: + d = Deadline() + d.cislo = cislo + d.typ = m.Deadline.TYP_CISLA + d.deadline = timezone.make_aware(datetime.datetime.combine(datetime.date(1994 + cislo.rocnik.rocnik, 6, int(cislo.poradi[0])), datetime.time.min)) + d.verejna_vysledkovka = cislo.verejna_vysledkovka + d.save() + continue if cislo.datum_deadline_soustredeni and cislo.datum_deadline_soustredeni == cislo.datum_preddeadline: d = Deadline() d.cislo = cislo d.typ = m.Deadline.TYP_PRVNI_A_SOUS d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline_soustredeni, datetime.time.min)) + datetime.timedelta(days=1) - d.verejna_vysledkovka = cislo.verejna_vysledkovka + d.verejna_vysledkovka = True d.save() else: if cislo.datum_deadline_soustredeni: @@ -38,14 +36,14 @@ def vytvor_deadliny(apps, schema_editor): d.cislo = cislo d.typ = m.Deadline.TYP_SOUS d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline_soustredeni, datetime.time.min)) + datetime.timedelta(days=1) - d.verejna_vysledkovka = cislo.verejna_vysledkovka + d.verejna_vysledkovka = True d.save() if cislo.datum_preddeadline: d = Deadline() d.cislo = cislo d.typ = m.Deadline.TYP_PRVNI d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_preddeadline, datetime.time.min)) + datetime.timedelta(days=1) - d.verejna_vysledkovka = cislo.verejna_vysledkovka + d.verejna_vysledkovka = True d.save() if cislo.datum_deadline: @@ -53,7 +51,7 @@ def vytvor_deadliny(apps, schema_editor): d.cislo = cislo d.typ = m.Deadline.TYP_CISLA d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline, datetime.time.min)) + datetime.timedelta(days=1) - d.verejna_vysledkovka = cislo.verejna_vysledkovka + d.verejna_vysledkovka = True d.save() diff --git a/seminar/migrations/0104_hodnoceni_deadline_body.py b/seminar/migrations/0104_hodnoceni_deadline_body.py index fe118b60..95009578 100644 --- a/seminar/migrations/0104_hodnoceni_deadline_body.py +++ b/seminar/migrations/0104_hodnoceni_deadline_body.py @@ -11,6 +11,12 @@ def prirad_deadliny(apps, schema_editor): Deadline = apps.get_model('seminar', 'Deadline') for h in Hodnoceni.objects.all(): + if h.cislo_body.rocnik.rocnik < 26: + # Deadline připravený v minulé migraci + h.deadline_body = h.cislo_body.deadline_v_cisle.get() + h.save() + continue + p = h.problem try: diff --git a/seminar/models/odevzdavatko.py b/seminar/models/odevzdavatko.py index 2fef5a09..77ed5018 100644 --- a/seminar/models/odevzdavatko.py +++ b/seminar/models/odevzdavatko.py @@ -104,6 +104,7 @@ class Hodnoceni(bm.SeminarModelBase): cislo_body = models.ForeignKey(am.Cislo, verbose_name='číslo pro body', related_name='hodnoceni', blank=True, null=True, on_delete=models.PROTECT) + # V ročníku < 26 nastaveno na deadline vygenerovaný pro původní cislo_body deadline_body = models.ForeignKey(am.Deadline, verbose_name='deadline pro body', related_name='hodnoceni', blank=True, null=True, on_delete=models.PROTECT) diff --git a/seminar/models/tvorba.py b/seminar/models/tvorba.py index d536caac..57813f39 100644 --- a/seminar/models/tvorba.py +++ b/seminar/models/tvorba.py @@ -328,6 +328,7 @@ class Deadline(SeminarModelBase): id = models.AutoField(primary_key=True) + # V ročníku < 26 nastaveno na datetime.datetime.combine(datetime.date(1994 + cislo.rocnik.rocnik, 6, int(cislo.poradi[0])), datetime.time.min) deadline = models.DateTimeField(blank=False, default=timezone.make_aware(datetime.datetime.combine(timezone.now(), datetime.time.max))) cislo = models.ForeignKey(Cislo, verbose_name='deadline v čísle',