|
|
|
# -*- 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, models
|
|
|
|
|
|
|
|
from django.db.models import Q
|
|
|
|
import django.db.models.deletion
|
|
|
|
|
|
|
|
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(
|
|
|
|
# Zakomentované fieldy by se už měly nacházet v příslušném problému
|
|
|
|
problem_ptr = uold,
|
|
|
|
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,
|
|
|
|
)
|
|
|
|
uold.save() # DULEZITE!!! Jinak Uloha.objects.create() přepíše všechny atributy Problému
|
|
|
|
unew.opravovatele.add(*uold.opravovatele.all())
|
|
|
|
|
|
|
|
# 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')
|
|
|
|
|
|
|
|
# XXX: Org-clanky neexistuji, tak je migrace ani nepodporuje.
|
|
|
|
clanky = Problem.objects.filter(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_old is None:
|
|
|
|
cislo = cl.cislo_reseni_old
|
|
|
|
elif cl.cislo_reseni_old is None:
|
|
|
|
cislo = cl.cislo_zadani_old
|
|
|
|
elif cl.cislo_reseni_old == cl.cislo_zadani_old:
|
|
|
|
cislo = cl.cislo_zadani_old
|
|
|
|
else:
|
|
|
|
raise ValueError("Různá čísla zadání a řešení u článku! (Článek: {})".format(cl.nazev))
|
|
|
|
|
|
|
|
clnew = Clanek.objects.create(
|
|
|
|
problem_ptr = cl,
|
|
|
|
# Problém by nemělo být potřeba upravovat
|
|
|
|
cislo = cislo,
|
|
|
|
# Body ignorujeme, protože už jsou v hodnocení
|
|
|
|
)
|
|
|
|
cl.save() # DULEZITE!!! Jinak Clanek.objects.create() přepíše všechny atributy Problému
|
|
|
|
|
|
|
|
# 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'))
|
|
|
|
#temata = Problem.objects.filter(id=635)
|
|
|
|
#temata = Problem.objects.filter(cislo_zadani_old__id=87)
|
|
|
|
for t in temata:
|
|
|
|
# Vymyslíme správně ročník:
|
|
|
|
if t.cislo_zadani_old is None and t.cislo_reseni_old is None:
|
|
|
|
rocnik = None
|
|
|
|
elif t.cislo_zadani_old is None:
|
|
|
|
rocnik = t.cislo_reseni_old.rocnik
|
|
|
|
elif t.cislo_reseni_old is None:
|
|
|
|
rocnik = t.cislo_zadani_old.rocnik
|
|
|
|
elif t.cislo_reseni_old.rocnik == t.cislo_zadani_old.rocnik:
|
|
|
|
rocnik = t.cislo_zadani_old.rocnik
|
|
|
|
else:
|
|
|
|
raise ValueError("Nelze mít téma přes více ročníků! (Téma: {}".format(t.nazev))
|
|
|
|
|
|
|
|
tnew = Tema.objects.create(
|
|
|
|
problem_ptr = t,
|
|
|
|
tema_typ = t.typ,
|
|
|
|
rocnik = rocnik,
|
|
|
|
)
|
|
|
|
t.save() # DULEZITE!!! Jinak Tema.objects.create() přepíše všechny atributy Problému
|
|
|
|
|
|
|
|
# Nody:
|
|
|
|
tnode = TemaVCisleNode(tema = tnew)
|
|
|
|
poskladej_strom(apps, tnode, t.text_zadani, t.text_reseni)
|
|
|
|
tnode.save()
|
|
|
|
|
|
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
('seminar', '0087_fix_polymorphism'),
|
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
# ashes to Ashes, dust to Dust....
|
|
|
|
migrations.RunPython(uloha_to_Uloha, migrations.RunPython.noop),
|
|
|
|
migrations.RunPython(tema_to_Tema, migrations.RunPython.noop),
|
|
|
|
migrations.RunPython(clanek_to_Clanek, migrations.RunPython.noop),
|
|
|
|
migrations.RunPython(konfery_rucne, migrations.RunPython.noop),
|
|
|
|
]
|