Browse Source

Spravne vyrobeni TreeNodu pro clanek

middleware_test
Pavel Turinsky (DebianVM @ Zr) 3 years ago
parent
commit
d66b8c3be2
  1. 24
      seminar/migrations/0058_problem_to_uloha_tema_clanek.py

24
seminar/migrations/0058_problem_to_uloha_tema_clanek.py

@ -78,7 +78,7 @@ def konfery_rucne(apps, schema_editor):
def clanek_to_Clanek(apps,schema_editor): def clanek_to_Clanek(apps,schema_editor):
Problem = apps.get_model('seminar', 'Problem') Problem = apps.get_model('seminar', 'Problem')
Clanek = apps.get_model('seminar', 'Clanek') Clanek = apps.get_model('seminar', 'Clanek')
ClanekNode = apps.get_model('seminar', 'ClanekNode') ReseniNode = apps.get_model('seminar', 'ReseniNode')
Text = apps.get_model('seminar', 'Text') Text = apps.get_model('seminar', 'Text')
TextNode = apps.get_model('seminar', 'TextNode') TextNode = apps.get_model('seminar', 'TextNode')
@ -105,10 +105,23 @@ def clanek_to_Clanek(apps,schema_editor):
cl.save() cl.save()
def Clanek_Treenody(apps, schema_editor):
Problem = apps.get_model('seminar', 'Problem')
Clanek = apps.get_model('seminar', 'Clanek')
ReseniNode = apps.get_model('seminar', 'ReseniNode')
Text = apps.get_model('seminar', 'Text')
TextNode = apps.get_model('seminar', 'TextNode')
for cl in Clanek.objects.all():
# Vyrobíme nody: # Vyrobíme nody:
clnode = ClanekNode(clanek = clnew) # Clanek nema vlastni node, ma (prave jedno) Reseni a to ma ReseniNode
poskladej_strom(apps, clnode, cl.text_zadani, cl.text_reseni) reseni = cl.reseni_set.all()
clnode.save() if len(reseni) != 1:
raise ValueError(f'Clanek {cl.id} ma vic reseni {len(reseni)} ({reseni})')
reseni = reseni[0]
resnode = ReseniNode(reseni=reseni)
poskladej_strom(apps, resnode, cl.text_zadani, cl.text_reseni)
resnode.save()
def fix_Clanek_Reseni(apps, schema_editor): def fix_Clanek_Reseni(apps, schema_editor):
Problem = apps.get_model('seminar', 'Problem') Problem = apps.get_model('seminar', 'Problem')
@ -139,11 +152,9 @@ def fix_Clanek_Reseni(apps, schema_editor):
if h.id != vzor_hodnoceni.id: if h.id != vzor_hodnoceni.id:
ostatni_hodnoceni.append(h) ostatni_hodnoceni.append(h)
resitele.extend(r.resitele.all()) resitele.extend(r.resitele.all())
print(f'*** cl={cl.id}, res={resitele}')
rr[0].resitele.set(resitele) rr[0].resitele.set(resitele)
rr[0].save() rr[0].save()
vzor_hodnoceni.save() vzor_hodnoceni.save()
print(f'vzor = {vzor_hodnoceni}, ostatni = {ostatni_hodnoceni}')
# Ted mame spravne databazi, jeste potrebujeme z databaze smazat po novu nepouzita hodnoceni # Ted mame spravne databazi, jeste potrebujeme z databaze smazat po novu nepouzita hodnoceni
for h in ostatni_hodnoceni: for h in ostatni_hodnoceni:
h.reseni.delete() h.reseni.delete()
@ -195,5 +206,6 @@ class Migration(migrations.Migration):
migrations.RunPython(tema_to_Tema, migrations.RunPython.noop), migrations.RunPython(tema_to_Tema, migrations.RunPython.noop),
migrations.RunPython(clanek_to_Clanek, migrations.RunPython.noop), migrations.RunPython(clanek_to_Clanek, migrations.RunPython.noop),
migrations.RunPython(fix_Clanek_Reseni, migrations.RunPython.noop), migrations.RunPython(fix_Clanek_Reseni, migrations.RunPython.noop),
migrations.RunPython(Clanek_Treenody, migrations.RunPython.noop),
migrations.RunPython(konfery_rucne, migrations.RunPython.noop), migrations.RunPython(konfery_rucne, migrations.RunPython.noop),
] ]

Loading…
Cancel
Save