Browse Source

Učesání datové migrace na deadliny

pull/3/head
Jonas Havelka 2 years ago
parent
commit
d582c43de5
  1. 61
      seminar/migrations/0103_deadline.py

61
seminar/migrations/0103_deadline.py

@ -3,7 +3,6 @@
import datetime
from django.db import migrations, models
import django.db.models.deletion
from django.db.models import F
from django.utils import timezone
import seminar.models as m
@ -15,44 +14,44 @@ def vytvor_deadliny(apps, schema_editor):
for cislo in Cislo.objects.all():
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()
Deadline.objects.create(
cislo=cislo,
typ=m.Deadline.TYP_CISLA,
deadline=timezone.make_aware(datetime.datetime.combine(datetime.date(1994 + cislo.rocnik.rocnik, 6, int(cislo.poradi[0])), datetime.time.min)),
verejna_vysledkovka=cislo.verejna_vysledkovka,
)
continue
def vytvor_deadline(date: datetime.date, typ):
Deadline.objects.create(
cislo=cislo,
typ=typ,
deadline=timezone.make_aware(datetime.datetime.combine(date, datetime.time.min)) + datetime.timedelta(days=1),
verejna_vysledkovka=True
)
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 = True
d.save()
vytvor_deadline(
date=cislo.datum_deadline_soustredeni,
typ=m.Deadline.TYP_PRVNI_A_SOUS
)
else:
if cislo.datum_deadline_soustredeni:
d = Deadline()
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 = True
d.save()
vytvor_deadline(
date=cislo.datum_deadline_soustredeni,
typ=m.Deadline.TYP_SOUS
)
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 = True
d.save()
vytvor_deadline(
date=cislo.datum_preddeadline,
typ=m.Deadline.TYP_PRVNI
)
if cislo.datum_deadline:
d = Deadline()
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 = True
d.save()
vytvor_deadline(
date=cislo.datum_deadline,
typ=m.Deadline.TYP_CISLA
)
class Migration(migrations.Migration):

Loading…
Cancel
Save