Browse Source

Doplnění deadlinů, větší rozptyl kontroly

pull/3/head
Jonas Havelka 2 years ago
parent
commit
d9912671ff
  1. 15
      seminar/migrations/0103_deadline.py
  2. 2
      seminar/migrations/0104_hodnoceni_deadline_body.py

15
seminar/migrations/0103_deadline.py

@ -3,6 +3,7 @@
import datetime import datetime
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
from django.db.models import F
from django.utils import timezone from django.utils import timezone
import seminar.models as m import seminar.models as m
@ -11,13 +12,19 @@ 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):
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.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.max)) 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 = cislo.verejna_vysledkovka
d.save() d.save()
else: else:
@ -25,14 +32,14 @@ def vytvor_deadliny(apps, schema_editor):
d = Deadline() d = Deadline()
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.max)) 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 = cislo.verejna_vysledkovka
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.max)) 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 = cislo.verejna_vysledkovka
d.save() d.save()
@ -40,7 +47,7 @@ def vytvor_deadliny(apps, schema_editor):
d = Deadline() d = Deadline()
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.max)) 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 = cislo.verejna_vysledkovka
d.save() d.save()

2
seminar/migrations/0104_hodnoceni_deadline_body.py

@ -15,7 +15,7 @@ def prirad_deadliny(apps, schema_editor):
h.deadline_body = d h.deadline_body = d
h.save() h.save()
if h.cislo_body and int(h.deadline_body.cislo.poradi) + 1 != int(h.cislo_body.poradi[0]): if h.cislo_body and (int(h.deadline_body.cislo.poradi) + 2 < int(h.cislo_body.poradi[0]) or int(h.deadline_body.cislo.poradi) > int(h.cislo_body.poradi[0])):
log.error(f"Hodnocení {h.id} se špatně změnilo číslo z {h.cislo_body} na {h.deadline_body.cislo}") log.error(f"Hodnocení {h.id} se špatně změnilo číslo z {h.cislo_body} na {h.deadline_body.cislo}")

Loading…
Cancel
Save