From 418eb7c17a42dc3509cd27cbc11ddb434a0fa35d Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Thu, 7 Nov 2019 22:19:23 +0100 Subject: [PATCH] =?UTF-8?q?Migrace:=20Nefunguje=20vol=C3=A1n=C3=AD=20metod?= 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):