Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
5.0 KiB
162 lines
5.0 KiB
![]()
5 years ago
|
# -*- 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_ptr = 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_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í
|
||
|
)
|
||
|
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_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,
|
||
|
)
|
||
|
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),
|
||
|
]
|