From 67e107a9eceb44842178ce2acca14e799875d48f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=26M=20testovac=C3=AD=20u=C5=BEivatel=20na=20Pavlov=C4=9B?= =?UTF-8?q?=20notebooku?= Date: Wed, 17 Jun 2020 19:56:00 +0000 Subject: [PATCH] =?UTF-8?q?P=C5=99id=C3=A1no=20=C4=8D=C3=ADslo=20ke=20?= =?UTF-8?q?=C4=8Dl=C3=A1nku?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/migrations/0084_clanek_cislo.py | 43 +++++++++++++++++++++++++ seminar/models.py | 5 ++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 seminar/migrations/0084_clanek_cislo.py diff --git a/seminar/migrations/0084_clanek_cislo.py b/seminar/migrations/0084_clanek_cislo.py new file mode 100644 index 00000000..03a8ff51 --- /dev/null +++ b/seminar/migrations/0084_clanek_cislo.py @@ -0,0 +1,43 @@ +# Generated by Django 2.2.13 on 2020-06-17 19:06 + +from django.db import migrations, models +import django.db.models.deletion +from seminar.treelib import get_parent + +def najdi_cislo(apps, schema_editor): + # + Clanek = apps.get_model('seminar', 'Clanek') + Hodnoceni = apps.get_model('seminar', 'Hodnoceni') + Reseni = apps.get_model('seminar', 'Reseni') + ReseniNode = apps.get_model('seminar', 'ReseniNode') + CisloNode = apps.get_model('seminar', 'CisloNode') + + for c in Clanek.objects.all(): + reseni = c.reseni_set + if (len(reseni) != 1): + raise ValueError("Článek k sobě má nejedno řešení!") + r = reseni[0] + aktualniNode = r.reseninode + while aktualniNode is not None: + if isinstance(aktualniNode, CisloNode): + c.cislo = aktualniNode.cislo + c.save() + break + aktualniNode = get_parent() + + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0083_auto_20200506_1952'), + ] + + operations = [ + migrations.AddField( + model_name='clanek', + name='cislo', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='vydane_clanky', to='seminar.Cislo', verbose_name='číslo vydání'), + ), + migrations.RunPython(najdi_cislo), + ] diff --git a/seminar/models.py b/seminar/models.py index 63d4a7b1..91eff9b3 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -733,7 +733,7 @@ class Problem(SeminarModelBase,PolymorphicModel): # FIXME: Tohle se liší podle typu problému, má se udělat polymorfně. # Zatím je tu jen dummy fail-safe default: nic není veřejné. return False - # FIXME: Tohle je blbost + # FIXME: Tohle je blbost return (self.cislo_zadani and self.cislo_zadani.verejne()) verejne.boolean = True @@ -795,6 +795,9 @@ class Clanek(Problem): verbose_name = 'Článek' verbose_name_plural = 'Články' + cislo = models.ForeignKey(Cislo, blank=True, null=True, on_delete=models.PROTECT, + verbose_name='číslo vydání', related_name='vydane_clanky') + def kod_v_rocniku(self): if self.stav == 'zadany': # Nemělo by být potřeba