From 87e51ac7449ad0c36d59c9aeb7920653696483b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Sat, 1 Oct 2022 14:01:29 +0200 Subject: [PATCH] =?UTF-8?q?J=C3=A1=20u=C5=BE=20nev=C3=ADm,=20jak=20ur?= =?UTF-8?q?=C4=8Dovat=20deadliny=20=C5=99e=C5=A1en=C3=AD=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/migrations/0103_deadline.py | 7 +++- .../0104_hodnoceni_deadline_body.py | 41 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/seminar/migrations/0103_deadline.py b/seminar/migrations/0103_deadline.py index 337f6365..406c7200 100644 --- a/seminar/migrations/0103_deadline.py +++ b/seminar/migrations/0103_deadline.py @@ -16,10 +16,15 @@ def vytvor_deadliny(apps, schema_editor): 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() + 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 diff --git a/seminar/migrations/0104_hodnoceni_deadline_body.py b/seminar/migrations/0104_hodnoceni_deadline_body.py index bc662479..66d8e61f 100644 --- a/seminar/migrations/0104_hodnoceni_deadline_body.py +++ b/seminar/migrations/0104_hodnoceni_deadline_body.py @@ -11,11 +11,50 @@ def prirad_deadliny(apps, schema_editor): Deadline = apps.get_model('seminar', 'Deadline') for h in Hodnoceni.objects.all(): + p = h.problem + + try: + u = p.uloha + if u.cislo_zadani is not None: + d = Deadline.objects.filter(cislo=u.cislo_zadani, deadline__gte=h.reseni.cas_doruceni).first() + h.deadline_body = d + h.save() + continue + + except Exception: + pass + + try: + c = p.clanek + if c.cislo is not None: + d = Deadline.objects.filter(cislo=c.cislo, deadline__gte=h.reseni.cas_doruceni).first() + h.deadline_body = d + h.save() + continue + + except Exception: + pass + + try: + t = p.tema + d = Deadline.objects.filter(cislo__rocnik=t.rocnik, deadline__gte=h.reseni.cas_doruceni).first() + + if d is None: + d = Deadline.objects.filter(cislo__rocnik=t.rocnik).last() + + h.deadline_body = d + h.save() + + except Exception: + pass + + log.warning(f"Deadline hodnocení {h.id} se nepodařil určit exaktnějším způsobem. Zkouším další.") + d = Deadline.objects.filter(deadline__gte=h.reseni.cas_doruceni).first() h.deadline_body = d h.save() - 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])): + if h.cislo_body and (int(h.deadline_body.cislo.poradi[0]) + 2 < int(h.cislo_body.poradi[0]) or int(h.deadline_body.cislo.poradi[0]) > 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}")