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): def vytvor_deadliny(apps, schema_editor):
Cislo = apps.get_model('seminar', 'Cislo') Cislo = apps.get_model('seminar', 'Cislo')
Deadline = apps.get_model('seminar', 'Deadline') Deadline = apps.get_model('seminar', 'Deadline')
Hodnoceni = apps.get_model('seminar', 'Hodnoceni')
for cislo in Cislo.objects.all(): for cislo in Cislo.objects.all():
if not (cislo.datum_deadline or cislo.datum_deadline_soustredeni or cislo.datum_preddeadline): if cislo.rocnik.rocnik < 26:
h = Hodnoceni.objects.filter(problem__uloha__cislo_zadani=cislo).order_by(F("reseni__cas_doruceni")).last() d = Deadline()
d.cislo = cislo
if h is None: d.typ = m.Deadline.TYP_CISLA
h = Hodnoceni.objects.filter(cislo_body=cislo).order_by(F("reseni__cas_doruceni")).last() 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
if h is not None: d.save()
cislo.datum_deadline = h.reseni.cas_doruceni.date() continue
cislo.save()
if cislo.datum_deadline_soustredeni and cislo.datum_deadline_soustredeni == cislo.datum_preddeadline: if cislo.datum_deadline_soustredeni and cislo.datum_deadline_soustredeni == cislo.datum_preddeadline:
d = Deadline() d = Deadline()
d.cislo = cislo d.cislo = cislo
d.typ = m.Deadline.TYP_PRVNI_A_SOUS 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.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() d.save()
else: else:
if cislo.datum_deadline_soustredeni: if cislo.datum_deadline_soustredeni:
@ -38,14 +36,14 @@ def vytvor_deadliny(apps, schema_editor):
d.cislo = cislo d.cislo = cislo
d.typ = m.Deadline.TYP_SOUS 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.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() d.save()
if cislo.datum_preddeadline: if cislo.datum_preddeadline:
d = Deadline() d = Deadline()
d.cislo = cislo d.cislo = cislo
d.typ = m.Deadline.TYP_PRVNI 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.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() d.save()
if cislo.datum_deadline: if cislo.datum_deadline:
@ -53,7 +51,7 @@ def vytvor_deadliny(apps, schema_editor):
d.cislo = cislo d.cislo = cislo
d.typ = m.Deadline.TYP_CISLA 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.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() 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') Deadline = apps.get_model('seminar', 'Deadline')
for h in Hodnoceni.objects.all(): 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 p = h.problem
try: 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', cislo_body = models.ForeignKey(am.Cislo, verbose_name='číslo pro body',
related_name='hodnoceni', blank=True, null=True, on_delete=models.PROTECT) 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', deadline_body = models.ForeignKey(am.Deadline, verbose_name='deadline pro body',
related_name='hodnoceni', blank=True, null=True, on_delete=models.PROTECT) 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) 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))) 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', cislo = models.ForeignKey(Cislo, verbose_name='deadline v čísle',

Loading…
Cancel
Save