LEdoian
6 years ago
1 changed files with 159 additions and 0 deletions
@ -0,0 +1,159 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.11.20 on 2019-05-17 17:44 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
from django.db.models import Q |
|||
|
|||
def poskladej_strom(apps, rodic, *texty): |
|||
Text = apps.get_model('seminar', 'Text') |
|||
TextNode = apps.get_model('seminar', 'TextNode') |
|||
if not rodic: |
|||
raise ValueError("Rodič musí být definovaný") |
|||
|
|||
uz_ma_deti = False |
|||
tn = None |
|||
for txt in texty: |
|||
if not txt: |
|||
continue |
|||
# Přidej do stromu: |
|||
textobj = Text.objects.create(na_web = txt) |
|||
textobj.save() |
|||
textnode = TextNode.objects.create(text = textobj) |
|||
textnode.save() |
|||
if not uz_ma_deti: |
|||
rodic.first_child = textnode |
|||
rodic.save() |
|||
tn = rodic.first_child |
|||
uz_ma_deti = True |
|||
else: |
|||
tn.succ = textnode |
|||
tn.save() |
|||
tn = tn.succ |
|||
|
|||
def uloha_to_Uloha(apps,schema_editor): |
|||
Problem = apps.get_model('seminar', 'Problem') |
|||
Uloha = apps.get_model('seminar', 'Uloha') |
|||
Text = apps.get_model('seminar', 'Text') |
|||
UlohaZadaniNode = apps.get_model('seminar', 'UlohaZadaniNode') |
|||
UlohaVzorakNode = apps.get_model('seminar', 'UlohaVzorakNode') |
|||
TextNode = apps.get_model('seminar', 'TextNode') |
|||
|
|||
ulohy = Problem.objects.filter(typ = 'uloha') |
|||
for uold in ulohy: |
|||
unew = Uloha.objects.create( |
|||
problem = uold, |
|||
# Zakomentované fieldy by se už měly nacházet v příslušném problému |
|||
#nazev = uold.nazev, |
|||
#stav = uold.stav, |
|||
#zamereni = uold.zamereni, |
|||
#poznamka = uold.poznamka, |
|||
#autor = uold.autor, |
|||
#kod = uold.kod, |
|||
cislo_zadani = uold.cislo_zadani_old, |
|||
cislo_reseni = uold.cislo_reseni_old, |
|||
max_body = uold.body, |
|||
#vytvoreno = uold.vytvoreno, |
|||
) |
|||
# unew.opravovatele.add(*uold.opravovatele.all()) |
|||
unew.save() |
|||
|
|||
# Nody: |
|||
zadani_node = UlohaZadaniNode.objects.create(uloha = unew) |
|||
poskladej_strom(apps, zadani_node, uold.text_zadani) |
|||
zadani_node.save() |
|||
vzorak_node = UlohaVzorakNode.objects.create(uloha = unew) |
|||
poskladej_strom(apps, vzorak_node, uold.text_reseni) |
|||
vzorak_node.save() |
|||
|
|||
def konfery_rucne(apps, schema_editor): |
|||
# Tohle dělat nebudu, máme aktuálně celou jednu. Ale "Errors should never pass silently" |
|||
Problem = apps.get_model('seminar', 'Problem') |
|||
pocet_konfer = Problem.objects.filter(typ = 'konfera').count() |
|||
if pocet_konfer > 0: |
|||
raise NotImplementedError("Zkonvertuj {} konfer na objekt Konfera ručně, prosím".format(pocet_konfer)) |
|||
|
|||
def clanek_to_Clanek(apps,schema_editor): |
|||
Problem = apps.get_model('seminar', 'Problem') |
|||
Clanek = apps.get_model('seminar', 'Clanek') |
|||
ClanekNode = apps.get_model('seminar', 'ClanekNode') |
|||
Text = apps.get_model('seminar', 'Text') |
|||
TextNode = apps.get_model('seminar', 'TextNode') |
|||
|
|||
clanky = Problem.objects.filter(Q(typ='org-clanek') | Q(typ='res-clanek')) |
|||
for cl in clanky: |
|||
# Vybereme vhodné číslo pro článek z čísla zadání a čísla řešení: |
|||
if cl.cislo_zadani is None: |
|||
cislo = cl.cislo_reseni |
|||
elif cl.cislo_reseni is None: |
|||
cislo = cl.cislo_zadani |
|||
elif cl.cislo_reseni == cl.cislo_zadani: |
|||
cislo = cl.cislo_zadani |
|||
else: |
|||
raise ValueError("Různá čísla zadání a řešení u článku!") |
|||
|
|||
clnew = Clanek.objects.create( |
|||
problem = cl, |
|||
# Problém by nemělo být potřeba upravovat |
|||
cislo = cislo, |
|||
# Body ignorujeme, protože už jsou v hodnocení |
|||
) |
|||
clnew.save() |
|||
|
|||
# Aktuálně nemáme v modelu informaci o tom, jestli je to org-článek |
|||
# nebo řešitelský článek. Aby se neztratila informace, poznamenám to do |
|||
# poznámky. |
|||
cl.poznamka += "\nTyp:\t{}".format(cl.typ) |
|||
cl.save() |
|||
|
|||
# Vyrobíme nody: |
|||
clnode = ClanekNode(clanek = clnew) |
|||
poskladej_strom(apps, clnode, cl.text_zadani, cl.text_reseni) |
|||
clnode.save() |
|||
|
|||
def tema_to_Tema(apps, schema_editor): |
|||
Problem = apps.get_model('seminar', 'Problem') |
|||
Tema = apps.get_model('seminar', 'Tema') |
|||
TemaVCisleNode = apps.get_model('seminar', 'TemaVCisleNode') |
|||
Text = apps.get_model('seminar', 'Text') |
|||
TextNode = apps.get_model('seminar', 'TextNode') |
|||
|
|||
temata = Problem.objects.filter(Q(typ = 'tema') | Q(typ='serial')) |
|||
for t in temata: |
|||
# Vymyslíme správně ročník: |
|||
if t.cislo_zadani is None: |
|||
rocnik = t.cislo_reseni.rocnik |
|||
elif t.cislo_reseni is None: |
|||
rocnik = t.cislo_zadani.rocnik |
|||
elif t.cislo_reseni.rocnik == t.cislo_zadani.rocnik: |
|||
rocnik = t.cislo_zadani.rocnik |
|||
else: |
|||
raise ValueError("Nelze mít téma přes více ročníků!") |
|||
|
|||
tnew = Tema.objects.create( |
|||
problem = t, |
|||
tema_typ = t.typ, |
|||
rocnik = rocnik, |
|||
) |
|||
tnew.save() |
|||
|
|||
# Nody: |
|||
tnode = TemaVCisleNode(tema = tnew) |
|||
poskladej_strom(apps, tnode, t.text_zadani, t.text_reseni) |
|||
tnode.save() |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('seminar', '0057_reseni_to_reseni_hodnoceni'), |
|||
] |
|||
|
|||
operations = [ |
|||
# ashes to Ashes, dust to Dust.... |
|||
migrations.RunPython(uloha_to_Uloha), |
|||
migrations.RunPython(tema_to_Tema), |
|||
migrations.RunPython(clanek_to_Clanek), |
|||
migrations.RunPython(konfery_rucne), |
|||
] |
Loading…
Reference in new issue