You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
3.8 KiB

# Generated by Django 3.2.15 on 2022-10-01 08:44
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
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.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.save()
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 = cislo.verejna_vysledkovka
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.save()
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 = cislo.verejna_vysledkovka
d.save()
class Migration(migrations.Migration):
dependencies = [
('seminar', '0102_osoba_jak_se_dozvedeli'),
]
operations = [
migrations.CreateModel(
name='Deadline',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('deadline', models.DateTimeField(default=timezone.make_aware(datetime.datetime.combine(timezone.now(), datetime.time.max)))),
('typ', models.CharField(choices=[('cisla', 'Deadline celého čísla'), ('prvni', 'První deadline'), ('prvniasous', 'Sousový a první deadline'), ('sous', 'Sousový deadline')], max_length=32, verbose_name='typ deadlinu')),
('verejna_vysledkovka', models.BooleanField(db_column='verejna_vysledkovka', default=False, verbose_name='veřejná výsledkovka')),
('cislo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='deadline_v_cisle', to='seminar.cislo', verbose_name='deadline v čísle')),
],
options={
'verbose_name': 'Deadline',
'verbose_name_plural': 'Deadliny',
'db_table': 'seminar_deadliny',
'ordering': ['deadline'],
},
),
migrations.RunPython(vytvor_deadliny, migrations.RunPython.noop),
]