Browse Source

Migrace zachovávající výsledkovky ročníku < 26

pull/3/head
Jonas Havelka 2 years ago
parent
commit
8dceaec349
  1. 26
      seminar/migrations/0103_deadline.py
  2. 6
      seminar/migrations/0104_hodnoceni_deadline_body.py
  3. 1
      seminar/models/odevzdavatko.py
  4. 1
      seminar/models/tvorba.py

26
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()

6
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:

1
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)

1
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',

Loading…
Cancel
Save