Anet
6 years ago
13 changed files with 401 additions and 166 deletions
@ -0,0 +1,82 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.11.15 on 2019-05-16 20:59 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations |
|||
|
|||
def spoj_k_organizatorum_osoby(apps, scema_editor): |
|||
Organizator = apps.get_model('seminar', 'Organizator') |
|||
Resitel = apps.get_model('seminar', 'Resitel') |
|||
Osoba = apps.get_model('seminar', 'Osoba') |
|||
for org in Organizator.objects.all(): |
|||
|
|||
# Spárování organizátora s osobou |
|||
user = org.user |
|||
resitele = Resitel.objects.filter(user=user) |
|||
if resitele.count() != 0: |
|||
osoba = resitele.first().osoba |
|||
else: |
|||
osoba = Osoba(user=user) |
|||
|
|||
# Přesun informací z usera do osoby |
|||
# pro řešitele již v minule migraci |
|||
osoba.jmeno = user.first_name |
|||
osoba.prijmeni = user.last_name |
|||
osoba.email = user.email |
|||
user.jmeno = "Použij osobu!" |
|||
user.prijmeni = "Použij osobu!" |
|||
user.email = "Použij osobu!" |
|||
user.save() |
|||
|
|||
# Přesun informací z organizátora do jeho osoby |
|||
osoba.prezdivka = org.prezdivka if org.prezdivka is not None else '' |
|||
osoba.foto = org.foto |
|||
|
|||
# Všechno uložit |
|||
osoba.save() |
|||
org.osoba = osoba |
|||
org.save() |
|||
|
|||
def fix_problem(apps, schema_editor): |
|||
Problem = apps.get_model('seminar', 'Problem') |
|||
Organizator = apps.get_model('seminar', 'Organizator') |
|||
for pr in Problem.objects.all(): |
|||
if pr.autor_old is not None: |
|||
pr.autor = Organizator.objects.filter(osoba__user=pr.autor_old).first() |
|||
else: |
|||
pr.autor = None |
|||
if pr.opravovatel is not None: |
|||
pr.opravovatele.add(Organizator.objects.filter(osoba__user=pr.opravovatel).first()) |
|||
pr.save() |
|||
|
|||
def fix_pohadka(apps, schema_editor): |
|||
Pohadka = apps.get_model('seminar', 'Pohadka') |
|||
Organizator = apps.get_model('seminar', 'Organizator') |
|||
for poh in Pohadka.objects.all(): |
|||
if poh.autor_old is not None: |
|||
poh.autor = Organizator.objects.filter(osoba__user=poh.autor_old).first() |
|||
else: |
|||
poh.autor = None |
|||
poh.save() |
|||
|
|||
def fix_novinka(apps, schema_editor): |
|||
Novinky = apps.get_model('seminar', 'Novinky') |
|||
Organizator = apps.get_model('seminar', 'Organizator') |
|||
for nov in Novinky.objects.all(): |
|||
nov.autor = Organizator.objects.filter(osoba__user=nov.autor_old).first() |
|||
nov.save() |
|||
|
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('seminar', '0051_resitel_to_osoba'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RunPython(spoj_k_organizatorum_osoby), |
|||
migrations.RunPython(fix_problem), |
|||
migrations.RunPython(fix_pohadka), |
|||
migrations.RunPython(fix_novinka), |
|||
] |
@ -0,0 +1,36 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.11.20 on 2019-05-16 21:26 |
|||
from __future__ import unicode_literals |
|||
|
|||
import datetime as dt |
|||
from django.db import migrations |
|||
|
|||
def rok_to_datetime(apps,schema_editor): |
|||
Organizator = apps.get_model('seminar','Organizator') |
|||
for o in Organizator.objects.all(): |
|||
rok = o.organizuje_od_roku |
|||
if rok: |
|||
o.organizuje_od = dt.datetime(rok,1,1) |
|||
rok = o.organizuje_do_roku |
|||
if rok: |
|||
o.organizuje_do = dt.datetime(rok,12,31) |
|||
o.save() |
|||
|
|||
def datetime_to_rok(apps,schema_editor): |
|||
Organizator = apps.get_model('seminar','Organizator') |
|||
for o in Organizator.objects.all(): |
|||
o.organizuje_od_roku = o.organizuje_od.year |
|||
o.organizuje_do_roku = o.organizuje_do.year |
|||
o.save() |
|||
|
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('seminar', '0052_user_to_organizator'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RunPython(rok_to_datetime, datetime_to_rok), |
|||
] |
@ -0,0 +1,51 @@ |
|||
# -*- 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 |
|||
|
|||
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') |
|||
|
|||
ulohy = Problem.objects.filter(typ = 'uloha') |
|||
for uold in ulohy: |
|||
zadani = Text.objects.create(na_web = uold.text_zadani) |
|||
vzorak = Text.objects.create(na_web = uold.text_reseni) |
|||
unew = Uloha.objects.create( |
|||
nazev = uold.nazev, |
|||
stav = uold.stav, |
|||
zamereni = uold.zamereni, |
|||
poznamka = uold.poznamka, |
|||
zadani = zadani, |
|||
vzorak = vzorak, |
|||
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() |
|||
|
|||
def tema_to_Tema(apps, schema_editor): |
|||
Problem = apps.get_model('seminar', 'Problem') |
|||
Tema = apps.get_model('seminar', 'Tema') |
|||
Text = apps.get_model('seminar', 'Text') |
|||
|
|||
temata = Problem.objects.filter(typ = 'tema') |
|||
# Bordel bordel bordel. Téma nemá zadání, je potřeba vyrobit TemaVCisleNode |
|||
|
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('seminar', '0053_organizator_organizuje_od_do'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.RunPython(uloha_to_Uloha), |
|||
] |
Loading…
Reference in new issue