From 281c66df1150eba59e15ad256823fc08fd0b7199 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Tue, 22 Oct 2019 21:39:34 +0200 Subject: [PATCH 1/5] Part1 --- seminar/models.py | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/seminar/models.py b/seminar/models.py index ddd24b5c..a3c69512 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -1147,6 +1147,7 @@ class TreeNode(PolymorphicModel): verbose_name = "TreeNode" verbose_name_plural = "TreeNody" + # TODO: Nechceme radši jako root vyžadovat přímo RocnikNode? root = models.ForeignKey('TreeNode', related_name="potomci_set", null = True, @@ -1176,7 +1177,11 @@ class TreeNode(PolymorphicModel): self.succ.print_tree(indent=indent) def __str__(self): - return self.nazev + if self.nazev: + return self.nazev + else: + #TODO: logování + return "Nepojmenovaný Treenode" class RocnikNode(TreeNode): class Meta: @@ -1186,8 +1191,6 @@ class RocnikNode(TreeNode): rocnik = models.OneToOneField(Rocnik, on_delete = models.PROTECT, # Pokud chci mazat ročník, musím si Node pořešit ručně verbose_name = "ročník") - def __str__(self): - return 'RocnikNode: '+str(self.rocnik) class CisloNode(TreeNode): class Meta: @@ -1197,16 +1200,12 @@ class CisloNode(TreeNode): cislo = models.OneToOneField(Cislo, on_delete = models.PROTECT, # Pokud chci mazat číslo, musím si Node pořešit ručně verbose_name = "číslo") - def __str__(self): - return 'CisloNode: '+str(self.cislo) class MezicisloNode(TreeNode): class Meta: db_table = 'seminar_nodes_mezicislo' verbose_name = 'Mezičíslo (Node)' verbose_name_plural = 'Mezičísla (Node)' - def __str__(self): - return 'MezicisloNode' class TemaVCisleNode(TreeNode): """ Obsahuje příspěvky k tématu v daném čísle """ @@ -1217,8 +1216,6 @@ class TemaVCisleNode(TreeNode): tema = models.ForeignKey(Tema, on_delete=models.PROTECT, # Pokud chci mazat téma, musím si Node pořešit ručně verbose_name = "téma v čísle") - def __str__(self): - return 'TemaVCisleNode: tema: '+str(self.tema) class KonferaNode(TreeNode): class Meta: @@ -1230,8 +1227,6 @@ class KonferaNode(TreeNode): verbose_name = "konfera", null=True, blank=False) - def __str__(self): - return 'KonferaNode: '+str(self.konfera) class ClanekNode(TreeNode): class Meta: @@ -1243,8 +1238,6 @@ class ClanekNode(TreeNode): verbose_name = "článek", null=True, blank=False) - def __str__(self): - return 'ClanekNode: '+str(self.clanek) class UlohaZadaniNode(TreeNode): class Meta: @@ -1256,8 +1249,6 @@ class UlohaZadaniNode(TreeNode): verbose_name = "úloha", null=True, blank=False) - def __str__(self): - return 'UlohaZadaniNode: '+str(self.uloha) class PohadkaNode(TreeNode): class Meta: @@ -1268,8 +1259,6 @@ class PohadkaNode(TreeNode): on_delete=models.PROTECT, # Pokud chci mazat pohádku, musím si Node pořešit ručně verbose_name = "pohádka", ) - def __str__(self): - return 'PohadkaNode: '+str(self.pohadka) class UlohaVzorakNode(TreeNode): class Meta: @@ -1281,8 +1270,6 @@ class UlohaVzorakNode(TreeNode): verbose_name = "úloha", null=True, blank=False) - def __str__(self): - return 'UlohaVzorakNode: '+str(self.uloha) class TextNode(TreeNode): class Meta: @@ -1292,8 +1279,6 @@ class TextNode(TreeNode): text = models.ForeignKey(Text, on_delete=models.PROTECT, verbose_name = 'text') - def __str__(self): - return 'TextNode: '+str(self.text) ## FIXME: Logiku přesunout do views. #class VysledkyBase(SeminarModelBase): From 34b785e235a846bb405949295ce717402ac9e10a Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Tue, 22 Oct 2019 21:51:16 +0200 Subject: [PATCH 2/5] A Migration --- seminar/migrations/0002_treenode_nazev.py | 104 ++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 seminar/migrations/0002_treenode_nazev.py diff --git a/seminar/migrations/0002_treenode_nazev.py b/seminar/migrations/0002_treenode_nazev.py new file mode 100644 index 00000000..ede4b697 --- /dev/null +++ b/seminar/migrations/0002_treenode_nazev.py @@ -0,0 +1,104 @@ +# Generated by Django 2.2.5 on 2019-09-26 19:35 + +from django.db import migrations, models + +def fix_RocnikNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'RocnikNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.rocnik)+" (RocnikNode)" + obj.save() + +def fix_CisloNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'CisloNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.cislo)+" (CisloNode)" + obj.save() + +def fix_MezicisloNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'MezicisloNode') + for obj in Objects.objects.all(): + if obj.prev: + if (obj.prev.get_real_instance_class() != CisloNode and + obj.prev.get_real_instance_class() != MezicisloNode): + raise ValueError("Předchůdce není číslo!") + posledni = obj.prev.cislo + obj.nazev = "Mezičíslo po čísle"+str(posledni)+" (MezicisloNode)" + elif obj.root: + if obj.root.get_real_instance_class() != RocnikNode: + raise ValueError("Kořen stromu není ročník!") + rocnik = obj.root.rocnik + obj.nazev = "První mezičíslo ročníku "+" (MezicisloNode)" + else: + print("!!!!! Nějaké neidentifikované mezičíslo !!!!!") + obj.nazev = "Neidentifikovatelné mezičíslo! (MezicisloNode)" + obj.save() + +def fix_TemaVCisleNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'TemaVCisleNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.tema)+" (TemaVCisleNode)" + obj.save() + +def fix_KonferaNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'KonferaNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.konfera)+" (KonferaNode)" + obj.save() + +def fix_ClanekNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'ClanekNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.clanek)+" (ClanekNode)" + obj.save() + +def fix_UlohaZadaniNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'UlohaZadaniNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.uloha)+" (UlohaZadaniNode)" + obj.save() + +def fix_PohadkaNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'PohadkaNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.pohadka)+" (PohadkaNode)" + obj.save() + +def fix_UlohaVzorakNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'UlohaVzorakNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.uloha)+" (UlohaVzorakNode)" + obj.save() + +def fix_TextNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'TextNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.text)+" (TextNode)" + obj.save() + +def fix_all_names(apps,schema_editor): + fix_RocnikNode_names(apps,schema_editor) + fix_CisloNode_names(apps,schema_editor) + fix_MezicisloNode_names(apps,schema_editor) + fix_TemaVCisleNode_names(apps,schema_editor) + fix_KonferaNode_names(apps,schema_editor) + fix_ClanekNode_names(apps,schema_editor) + fix_UlohaZadaniNode_names(apps,schema_editor) + fix_PohadkaNode_names(apps,schema_editor) + fix_UlohaVzorakNode_names(apps,schema_editor) + fix_TextNode_names(apps,schema_editor) + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0001_reset'), + ] + + operations = [ + migrations.AddField( + model_name='treenode', + name='nazev', + field=models.TextField(help_text='Tento název se zobrazuje v nabídkách pro výběr vhodného TreeNode', null=True, verbose_name='název tohoto node'), + ), + migrations.RunPython(fix_all_names), + ] From 4f499330b13bf3e8a182acd4e913c4268f4838e5 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Wed, 23 Oct 2019 22:24:07 +0200 Subject: [PATCH 3/5] =?UTF-8?q?P=C5=99id=C3=A1na=20funkce=20na=20aktualiza?= =?UTF-8?q?ci=20n=C3=A1zvu=20*Nod=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/migrations/0002_treenode_nazev.py | 101 ++++------------------ seminar/models.py | 53 ++++++++++++ 2 files changed, 70 insertions(+), 84 deletions(-) diff --git a/seminar/migrations/0002_treenode_nazev.py b/seminar/migrations/0002_treenode_nazev.py index ede4b697..896ca744 100644 --- a/seminar/migrations/0002_treenode_nazev.py +++ b/seminar/migrations/0002_treenode_nazev.py @@ -2,91 +2,24 @@ from django.db import migrations, models -def fix_RocnikNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'RocnikNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.rocnik)+" (RocnikNode)" - obj.save() - -def fix_CisloNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'CisloNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.cislo)+" (CisloNode)" - obj.save() - -def fix_MezicisloNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'MezicisloNode') - for obj in Objects.objects.all(): - if obj.prev: - if (obj.prev.get_real_instance_class() != CisloNode and - obj.prev.get_real_instance_class() != MezicisloNode): - raise ValueError("Předchůdce není číslo!") - posledni = obj.prev.cislo - obj.nazev = "Mezičíslo po čísle"+str(posledni)+" (MezicisloNode)" - elif obj.root: - if obj.root.get_real_instance_class() != RocnikNode: - raise ValueError("Kořen stromu není ročník!") - rocnik = obj.root.rocnik - obj.nazev = "První mezičíslo ročníku "+" (MezicisloNode)" - else: - print("!!!!! Nějaké neidentifikované mezičíslo !!!!!") - obj.nazev = "Neidentifikovatelné mezičíslo! (MezicisloNode)" - obj.save() - -def fix_TemaVCisleNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'TemaVCisleNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.tema)+" (TemaVCisleNode)" - obj.save() - -def fix_KonferaNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'KonferaNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.konfera)+" (KonferaNode)" - obj.save() - -def fix_ClanekNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'ClanekNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.clanek)+" (ClanekNode)" - obj.save() - -def fix_UlohaZadaniNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'UlohaZadaniNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.uloha)+" (UlohaZadaniNode)" - obj.save() - -def fix_PohadkaNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'PohadkaNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.pohadka)+" (PohadkaNode)" - obj.save() - -def fix_UlohaVzorakNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'UlohaVzorakNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.uloha)+" (UlohaVzorakNode)" - obj.save() - -def fix_TextNode_names(apps,schema_editor): - Objects = apps.get_model('seminar', 'TextNode') - for obj in Objects.objects.all(): - obj.nazev = str(obj.text)+" (TextNode)" - obj.save() - def fix_all_names(apps,schema_editor): - fix_RocnikNode_names(apps,schema_editor) - fix_CisloNode_names(apps,schema_editor) - fix_MezicisloNode_names(apps,schema_editor) - fix_TemaVCisleNode_names(apps,schema_editor) - fix_KonferaNode_names(apps,schema_editor) - fix_ClanekNode_names(apps,schema_editor) - fix_UlohaZadaniNode_names(apps,schema_editor) - fix_PohadkaNode_names(apps,schema_editor) - fix_UlohaVzorakNode_names(apps,schema_editor) - fix_TextNode_names(apps,schema_editor) - + for objtype in [ + "RocnikNode", + "CisloNode", + "MezicisloNode", + "TemaVCisleNode", + "KonferaNode", + "ClanekNode", + "UlohaZadaniNode", + "PohadkaNode", + "UlohaVzorakNode", + "TextNode", + ]: + Objects = apps.get_model('seminar', objtype) + for obj in Objects.objects.all(): + obj.aktualizuj_nazev() + # Better save than sorry + obj.save() class Migration(migrations.Migration): diff --git a/seminar/models.py b/seminar/models.py index a3c69512..9eefdec4 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -1192,6 +1192,10 @@ class RocnikNode(TreeNode): on_delete = models.PROTECT, # Pokud chci mazat ročník, musím si Node pořešit ručně verbose_name = "ročník") + def aktualizuj_nazev(self): + self.nazev = "RocnikNode: "+str(self.rocnik) + self.save() + class CisloNode(TreeNode): class Meta: db_table = 'seminar_nodes_cislo' @@ -1201,12 +1205,33 @@ class CisloNode(TreeNode): on_delete = models.PROTECT, # Pokud chci mazat číslo, musím si Node pořešit ručně verbose_name = "číslo") + def aktualizuj_nazev(self): + self.nazev = "CisloNode: "+str(self.cislo) + self.save() + class MezicisloNode(TreeNode): class Meta: db_table = 'seminar_nodes_mezicislo' verbose_name = 'Mezičíslo (Node)' verbose_name_plural = 'Mezičísla (Node)' + def aktualizuj_nazev(self): + if self.prev: + if (self.prev.get_real_instance_class() != CisloNode and + self.prev.get_real_instance_class() != MezicisloNode): + raise ValueError("Předchůdce není číslo!") + posledni = self.prev.cislo + self.nazev = "MezicisloNode: Mezičíslo po čísle"+str(posledni) + elif self.root: + if self.root.get_real_instance_class() != RocnikNode: + raise ValueError("Kořen stromu není ročník!") + rocnik = self.root.rocnik + self.nazev = "MezicisloNode: První mezičíslo ročníku "+str(rocnik) + else: + print("!!!!! Nějaké neidentifikované mezičíslo !!!!!") + self.nazev = "MezicisloNode: Neidentifikovatelné mezičíslo!" + self.save() + class TemaVCisleNode(TreeNode): """ Obsahuje příspěvky k tématu v daném čísle """ class Meta: @@ -1217,6 +1242,10 @@ class TemaVCisleNode(TreeNode): on_delete=models.PROTECT, # Pokud chci mazat téma, musím si Node pořešit ručně verbose_name = "téma v čísle") + def aktualizuj_nazev(self): + self.nazev = "TemaVCisleNode: "+str(self.tema) + self.save() + class KonferaNode(TreeNode): class Meta: db_table = 'seminar_nodes_konfera' @@ -1228,6 +1257,10 @@ class KonferaNode(TreeNode): null=True, blank=False) + def aktualizuj_nazev(self): + self.nazev = "KonferaNode: "+str(self.konfera) + self.save() + class ClanekNode(TreeNode): class Meta: db_table = 'seminar_nodes_clanek' @@ -1239,6 +1272,10 @@ class ClanekNode(TreeNode): null=True, blank=False) + def aktualizuj_nazev(self): + self.nazev = "ClanekNode: "+str(self.clanek) + self.save() + class UlohaZadaniNode(TreeNode): class Meta: db_table = 'seminar_nodes_uloha_zadani' @@ -1250,6 +1287,10 @@ class UlohaZadaniNode(TreeNode): null=True, blank=False) + def aktualizuj_nazev(self): + self.nazev = "UlohaZadaniNode: "+str(self.uloha) + self.save() + class PohadkaNode(TreeNode): class Meta: db_table = 'seminar_nodes_pohadka' @@ -1260,6 +1301,10 @@ class PohadkaNode(TreeNode): verbose_name = "pohádka", ) + def aktualizuj_nazev(self): + self.nazev = "PohadkaNode: "+str(self.pohadka) + self.save() + class UlohaVzorakNode(TreeNode): class Meta: db_table = 'seminar_nodes_uloha_vzorak' @@ -1271,6 +1316,10 @@ class UlohaVzorakNode(TreeNode): null=True, blank=False) + def aktualizuj_nazev(self): + self.nazev = "UlohaVzorakNode: "+str(self.uloha) + self.save() + class TextNode(TreeNode): class Meta: db_table = 'seminar_nodes_obsah' @@ -1279,6 +1328,10 @@ class TextNode(TreeNode): text = models.ForeignKey(Text, on_delete=models.PROTECT, verbose_name = 'text') + + def aktualizuj_nazev(self): + self.nazev = "TextNode: "+str(self.text) + self.save() ## FIXME: Logiku přesunout do views. #class VysledkyBase(SeminarModelBase): From 418eb7c17a42dc3509cd27cbc11ddb434a0fa35d Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Thu, 7 Nov 2019 22:19:23 +0100 Subject: [PATCH 4/5] =?UTF-8?q?Migrace:=20Nefunguje=20vol=C3=A1n=C3=AD=20m?= =?UTF-8?q?etod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert souboru seminar/migrations/0002_treenode_nazev.py --- seminar/migrations/0002_treenode_nazev.py | 104 ++++++++++++++++++---- 1 file changed, 87 insertions(+), 17 deletions(-) diff --git a/seminar/migrations/0002_treenode_nazev.py b/seminar/migrations/0002_treenode_nazev.py index 896ca744..1219c339 100644 --- a/seminar/migrations/0002_treenode_nazev.py +++ b/seminar/migrations/0002_treenode_nazev.py @@ -2,24 +2,94 @@ from django.db import migrations, models +# Migrace nejspíš neumí volat metody modelů: +# https://stackoverflow.com/questions/28777338/django-migrations-runpython-not-able-to-call-model-methods#37685925 + +def fix_RocnikNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'RocnikNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.rocnik)+" (RocnikNode)" + obj.save() + +def fix_CisloNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'CisloNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.cislo)+" (CisloNode)" + obj.save() + +def fix_MezicisloNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'MezicisloNode') + for obj in Objects.objects.all(): + if obj.prev: + if (obj.prev.get_real_instance_class() != CisloNode and + obj.prev.get_real_instance_class() != MezicisloNode): + raise ValueError("Předchůdce není číslo!") + posledni = obj.prev.cislo + obj.nazev = "Mezičíslo po čísle"+str(posledni)+" (MezicisloNode)" + elif obj.root: + if obj.root.get_real_instance_class() != RocnikNode: + raise ValueError("Kořen stromu není ročník!") + rocnik = obj.root.rocnik + obj.nazev = "První mezičíslo ročníku "+" (MezicisloNode)" + else: + print("!!!!! Nějaké neidentifikované mezičíslo !!!!!") + obj.nazev = "Neidentifikovatelné mezičíslo! (MezicisloNode)" + obj.save() + +def fix_TemaVCisleNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'TemaVCisleNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.tema)+" (TemaVCisleNode)" + obj.save() + +def fix_KonferaNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'KonferaNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.konfera)+" (KonferaNode)" + obj.save() + +def fix_ClanekNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'ClanekNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.clanek)+" (ClanekNode)" + obj.save() + +def fix_UlohaZadaniNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'UlohaZadaniNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.uloha)+" (UlohaZadaniNode)" + obj.save() + +def fix_PohadkaNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'PohadkaNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.pohadka)+" (PohadkaNode)" + obj.save() + +def fix_UlohaVzorakNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'UlohaVzorakNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.uloha)+" (UlohaVzorakNode)" + obj.save() + +def fix_TextNode_names(apps,schema_editor): + Objects = apps.get_model('seminar', 'TextNode') + for obj in Objects.objects.all(): + obj.nazev = str(obj.text)+" (TextNode)" + obj.save() + def fix_all_names(apps,schema_editor): - for objtype in [ - "RocnikNode", - "CisloNode", - "MezicisloNode", - "TemaVCisleNode", - "KonferaNode", - "ClanekNode", - "UlohaZadaniNode", - "PohadkaNode", - "UlohaVzorakNode", - "TextNode", - ]: - Objects = apps.get_model('seminar', objtype) - for obj in Objects.objects.all(): - obj.aktualizuj_nazev() - # Better save than sorry - obj.save() + fix_RocnikNode_names(apps,schema_editor) + fix_CisloNode_names(apps,schema_editor) + fix_MezicisloNode_names(apps,schema_editor) + fix_TemaVCisleNode_names(apps,schema_editor) + fix_KonferaNode_names(apps,schema_editor) + fix_ClanekNode_names(apps,schema_editor) + fix_UlohaZadaniNode_names(apps,schema_editor) + fix_PohadkaNode_names(apps,schema_editor) + fix_UlohaVzorakNode_names(apps,schema_editor) + fix_TextNode_names(apps,schema_editor) + class Migration(migrations.Migration): From 8ff93a0c5c5bc5ac2b7adc141d716ebfc81fbae4 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Fri, 8 Nov 2019 00:31:19 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Save=20hook,=20kter=C3=BD=20aktualizuje=20n?= =?UTF-8?q?=C3=A1zvy=20*Nod=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/models.py | 55 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/seminar/models.py b/seminar/models.py index 9eefdec4..055ab07b 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -384,6 +384,10 @@ class Rocnik(SeminarModelBase): cache.set(name, c, 300) return c + def save(self): + super().save() + # *Node.save() aktualizuje název *Nodu. + self.rocniknode.save() def cislo_pdf_filename(self, filename): rocnik = str(self.rocnik.rocnik) @@ -477,6 +481,11 @@ class Cislo(SeminarModelBase): return None return c + def save(self): + super().save() + # *Node.save() aktualizuje název *Nodu. + self.cislonode.save() + @reversion.register(ignore_duplicates=True) class Organizator(SeminarModelBase): # zmena dedicnosti z models.Model na SeminarModelBase, potencialni vznik bugu @@ -707,6 +716,12 @@ class Tema(Problem): return "t{}".format(self.kod) return '' + def save(self): + super().save() + # *Node.save() aktualizuje název *Nodu. + for tvcn in self_temavcislenode_set: + tvcn.save() + class Clanek(Problem): class Meta: db_table = 'seminar_clanky' @@ -727,6 +742,11 @@ class Clanek(Problem): return "c{}".format(self.kod) return '' + def save(self): + super().save() + # *Node.save() aktualizuje název *Nodu. + self.claneknode.save() + class Text(SeminarModelBase): class Meta: db_table = 'seminar_texty' @@ -744,6 +764,12 @@ class Text(SeminarModelBase): # obrázky mají návaznost opačným směrem (vazba z druhé strany) + def save(self): + super().save() + # *Node.save() aktualizuje název *Nodu. + for tn in self.textnode_set: + tn.save() + class Uloha(Problem): @@ -778,6 +804,12 @@ class Uloha(Problem): return name return '' + def save(self): + super().save() + # *Node.save() aktualizuje název *Nodu. + self.ulohazadaninode.save() + self.ulohavzoraknode.save() + @reversion.register(ignore_duplicates=True) class Reseni(SeminarModelBase): @@ -959,6 +991,10 @@ class Pohadka(SeminarModelBase): uryvek = self.text if len(self.text) < 50 else self.text[:(50-3)]+"..." return uryvek + def save(self): + super().save() + # *Node.save() aktualizuje název *Nodu. + self.pohadkanode.save() @reversion.register(ignore_duplicates=True) class Soustredeni_Ucastnici(SeminarModelBase): @@ -1069,6 +1105,11 @@ class Konfera(models.Model): def __str__(self): return "{}: ({})".format(self.nazev, self.soustredeni) + def save(self): + super().save() + # *Node.save() aktualizuje název *Nodu. + self.konferanode.save() + # Vazebna tabulka. Mozna se generuje automaticky. @reversion.register(ignore_duplicates=True) @@ -1182,6 +1223,10 @@ class TreeNode(PolymorphicModel): else: #TODO: logování return "Nepojmenovaný Treenode" + + def save(self): + self.aktualizuj_nazev() + super().save() class RocnikNode(TreeNode): class Meta: @@ -1194,7 +1239,6 @@ class RocnikNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "RocnikNode: "+str(self.rocnik) - self.save() class CisloNode(TreeNode): class Meta: @@ -1207,7 +1251,6 @@ class CisloNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "CisloNode: "+str(self.cislo) - self.save() class MezicisloNode(TreeNode): class Meta: @@ -1230,7 +1273,6 @@ class MezicisloNode(TreeNode): else: print("!!!!! Nějaké neidentifikované mezičíslo !!!!!") self.nazev = "MezicisloNode: Neidentifikovatelné mezičíslo!" - self.save() class TemaVCisleNode(TreeNode): """ Obsahuje příspěvky k tématu v daném čísle """ @@ -1244,7 +1286,6 @@ class TemaVCisleNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "TemaVCisleNode: "+str(self.tema) - self.save() class KonferaNode(TreeNode): class Meta: @@ -1259,7 +1300,6 @@ class KonferaNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "KonferaNode: "+str(self.konfera) - self.save() class ClanekNode(TreeNode): class Meta: @@ -1274,7 +1314,6 @@ class ClanekNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "ClanekNode: "+str(self.clanek) - self.save() class UlohaZadaniNode(TreeNode): class Meta: @@ -1289,7 +1328,6 @@ class UlohaZadaniNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "UlohaZadaniNode: "+str(self.uloha) - self.save() class PohadkaNode(TreeNode): class Meta: @@ -1303,7 +1341,6 @@ class PohadkaNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "PohadkaNode: "+str(self.pohadka) - self.save() class UlohaVzorakNode(TreeNode): class Meta: @@ -1318,7 +1355,6 @@ class UlohaVzorakNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "UlohaVzorakNode: "+str(self.uloha) - self.save() class TextNode(TreeNode): class Meta: @@ -1331,7 +1367,6 @@ class TextNode(TreeNode): def aktualizuj_nazev(self): self.nazev = "TextNode: "+str(self.text) - self.save() ## FIXME: Logiku přesunout do views. #class VysledkyBase(SeminarModelBase):