Přidána funkce na aktualizaci názvu *Nodů
This commit is contained in:
parent
34b785e235
commit
4f499330b1
2 changed files with 70 additions and 84 deletions
|
@ -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):
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue