From e6842af2a8db057dfc524f65789a8ff5465921f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Wed, 12 Oct 2022 14:27:44 +0200 Subject: [PATCH] =?UTF-8?q?Polymorfismus=20v=20migraci=20l=C3=A9pe.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0104_hodnoceni_deadline_body.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/seminar/migrations/0104_hodnoceni_deadline_body.py b/seminar/migrations/0104_hodnoceni_deadline_body.py index 1f34654e..7a3d7a6e 100644 --- a/seminar/migrations/0104_hodnoceni_deadline_body.py +++ b/seminar/migrations/0104_hodnoceni_deadline_body.py @@ -11,7 +11,7 @@ def prirad_deadliny(apps, schema_editor): Deadline = apps.get_model('seminar', 'Deadline') for h in Hodnoceni.objects.all(): - if h.cislo_body is not None and h.cislo_body.rocnik.rocnik < 26: + if h.cislo_body is not None and h.cislo_body.rocnik.rocnik < -1: # Deadline připravený v minulé migraci h.deadline_body = h.cislo_body.deadline_v_cisle.get() h.save() @@ -19,7 +19,7 @@ def prirad_deadliny(apps, schema_editor): p = h.problem - try: + if p.polymorphic_ctype.model == 'tema': t = p.tema d = Deadline.objects.filter(cislo__rocnik=t.rocnik, deadline__gte=h.reseni.cas_doruceni).first() @@ -31,24 +31,16 @@ def prirad_deadliny(apps, schema_editor): h.save() continue - except Exception: - pass - - cislo = None - try: + if p.polymorphic_ctype.model == 'uloha': u = p.uloha cislo = u.cislo_zadani - except Exception: - pass - try: + if p.polymorphic_ctype.model == 'clanek': c = p.clanek if c.cislo is not None: cislo = c.cislo - except Exception: - pass if cislo is None: cislo = h.cislo_body @@ -68,6 +60,8 @@ def prirad_deadliny(apps, schema_editor): h.deadline_body = d h.save() + # Zběžná kontrola. Předpokládá, že M&M má méně než 10 čísel v ročníku + # a že první znak pořadí je int určující dané pořadí (schroustání 7-8). 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])