Merge branch 'data_migrations' of gimli.ms.mff.cuni.cz:/akce/mam/git/mamweb into data_migrations
This commit is contained in:
commit
cad478cd99
2 changed files with 47 additions and 0 deletions
43
seminar/migrations/0084_clanek_cislo.py
Normal file
43
seminar/migrations/0084_clanek_cislo.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
# Generated by Django 2.2.13 on 2020-06-17 19:06
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
from seminar.treelib import get_parent
|
||||||
|
|
||||||
|
def najdi_cislo(apps, schema_editor):
|
||||||
|
#
|
||||||
|
Clanek = apps.get_model('seminar', 'Clanek')
|
||||||
|
Hodnoceni = apps.get_model('seminar', 'Hodnoceni')
|
||||||
|
Reseni = apps.get_model('seminar', 'Reseni')
|
||||||
|
ReseniNode = apps.get_model('seminar', 'ReseniNode')
|
||||||
|
CisloNode = apps.get_model('seminar', 'CisloNode')
|
||||||
|
|
||||||
|
for c in Clanek.objects.all():
|
||||||
|
reseni = c.reseni_set
|
||||||
|
if (len(reseni) != 1):
|
||||||
|
raise ValueError("Článek k sobě má nejedno řešení!")
|
||||||
|
r = reseni[0]
|
||||||
|
aktualniNode = r.reseninode
|
||||||
|
while aktualniNode is not None:
|
||||||
|
if isinstance(aktualniNode, CisloNode):
|
||||||
|
c.cislo = aktualniNode.cislo
|
||||||
|
c.save()
|
||||||
|
break
|
||||||
|
aktualniNode = get_parent()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('seminar', '0083_auto_20200506_1952'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='clanek',
|
||||||
|
name='cislo',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='vydane_clanky', to='seminar.Cislo', verbose_name='číslo vydání'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(najdi_cislo),
|
||||||
|
]
|
|
@ -733,6 +733,7 @@ class Problem(SeminarModelBase,PolymorphicModel):
|
||||||
# FIXME: Tohle se liší podle typu problému, má se udělat polymorfně.
|
# FIXME: Tohle se liší podle typu problému, má se udělat polymorfně.
|
||||||
# Zatím je tu jen dummy fail-safe default: nic není veřejné.
|
# Zatím je tu jen dummy fail-safe default: nic není veřejné.
|
||||||
return False
|
return False
|
||||||
|
# FIXME: Tohle je blbost
|
||||||
return (self.cislo_zadani and self.cislo_zadani.verejne())
|
return (self.cislo_zadani and self.cislo_zadani.verejne())
|
||||||
verejne.boolean = True
|
verejne.boolean = True
|
||||||
|
|
||||||
|
@ -794,6 +795,9 @@ class Clanek(Problem):
|
||||||
verbose_name = 'Článek'
|
verbose_name = 'Článek'
|
||||||
verbose_name_plural = 'Články'
|
verbose_name_plural = 'Články'
|
||||||
|
|
||||||
|
cislo = models.ForeignKey(Cislo, blank=True, null=True, on_delete=models.PROTECT,
|
||||||
|
verbose_name='číslo vydání', related_name='vydane_clanky')
|
||||||
|
|
||||||
def kod_v_rocniku(self):
|
def kod_v_rocniku(self):
|
||||||
if self.stav == 'zadany':
|
if self.stav == 'zadany':
|
||||||
# Nemělo by být potřeba
|
# Nemělo by být potřeba
|
||||||
|
|
Loading…
Reference in a new issue