# Generated by Django 3.2.15 on 2022-10-09 10:14

from django.db import migrations
from seminar.models import Deadline


def vrat_deadliny(apps, schema_editor):
    Cislo = apps.get_model('seminar', 'Cislo')

    for cislo in Cislo.objects.all():
        prvni_deadline = cislo.deadline_v_cisle.filter(typ=Deadline.TYP_PRVNI).last()
        sous_deadline = cislo.deadline_v_cisle.filter(typ=Deadline.TYP_SOUS).last()
        prvni_a_sous_deadline = cislo.deadline_v_cisle.filter(typ=Deadline.TYP_PRVNI_A_SOUS).last()
        posledni_deadline = cislo.deadline_v_cisle.filter(typ=Deadline.TYP_CISLA).last()

        if prvni_a_sous_deadline is not None:
            cislo.datum_deadline_soustredeni = prvni_a_sous_deadline.deadline.date()
            cislo.datum_preddeadline = prvni_a_sous_deadline.deadline.date()
        else:
            if sous_deadline is not None:
                cislo.datum_deadline_soustredeni = sous_deadline.deadline.date()
            if prvni_deadline is not None:
                cislo.datum_preddeadline = prvni_deadline.deadline.date()

        if posledni_deadline:
            cislo.datum_deadline = posledni_deadline.deadline.date()

        cislo.save()

class Migration(migrations.Migration):

    dependencies = [
        ('seminar', '0104_hodnoceni_deadline_body'),
    ]

    operations = [
        migrations.RunPython(migrations.RunPython.noop, vrat_deadliny),
        migrations.RemoveField(
            model_name='cislo',
            name='datum_deadline',
        ),
        migrations.RemoveField(
            model_name='cislo',
            name='datum_deadline_soustredeni',
        ),
        migrations.RemoveField(
            model_name='cislo',
            name='datum_preddeadline',
        ),
    ]