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.
 
 
 
 
 
 

102 lines
5.2 KiB

# -*- coding: utf-8 -*-
import datetime
import random
import django.contrib.auth
from django.db import transaction
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
User = django.contrib.auth.get_user_model()
@transaction.atomic
def create_test_data(size = 6, rnd = None):
assert size >= 1
# pevna pseudo-nahodnost
rnd = rnd or random.Random(x=42)
# static URL stranky
s = Site.objects.filter(name="example.com")
f = FlatPage.objects.create(url="/", title="Seminář M&M", content = "<p>V&iacute;tejte na str&aacute;nce semin&aacute;ře MaM!</p>")
f.sites.add(s[0])
f.save()
# users
admin = User.objects.create_superuser(username='admin', email='', password='admin')
usernames = ['anet', 'bara', 'cyril', 'david', 'eva', 'filip']
orgs = []
for org in usernames[:size]:
o = User.objects.create_user(username=org, password=org)
o.first_name = org.capitalize()
o.save()
orgs.append(o)
# skoly
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='101 00', ulice=u'Krátká 5', nazev=u'První ZŠ', je_zs=True, je_ss=False)
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='101 00', ulice=u'Krátká 5', nazev=u'První SŠ', je_zs=False, je_ss=True)
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='102 00', ulice=u'Dlouhá 5', nazev=u'Druhá SŠ', je_zs=False, je_ss=True)
Skola.objects.create(mesto = u'Praha', stat='CZ', psc='103 00', ulice=u'Široká 3', nazev=u'Třetí SŠ a ZŠ', je_zs=True, je_ss=True)
Skola.objects.create(mesto = u'Ostrava', stat='CZ', psc='700 00', ulice=u'Hluboká 42', nazev=u'Hutní gympl', je_zs=False, je_ss=True)
Skola.objects.create(mesto = u'Humenné', stat='SK', psc='012 34', ulice=u'Pltká 1', nazev=u'Sredná škuola', je_zs=False, je_ss=True)
# resitele
jmena_m = ['Aleš', 'Tomáš', 'Martin', 'Jakub', 'Petr', 'Lukáš', 'Cyril']
jmena_f = ['Eva', 'Karolína', 'Zuzana', 'Sylvie', 'Iva', 'Jana', 'Marie']
prijmeni_m = ['Novotný', 'Svoboda', 'Pecha', 'Kořen', 'Holan', 'Uhlíř', 'Chytráček', 'Pokora', 'Koch', 'Szegedy', 'Rudý']
prijmeni_f = ['Novotná', 'Svobodová', 'Machová', 'Zelená', 'Yu-Xin', 'Mlsná', 'Dubná', 'Mrkvová', 'Suchá', 'Lovelace', 'Holcová']
for i in range(3*size):
skola = rnd.choice(Skola.objects.all())
pohlavi = rnd.randint(0,1)
jmeno = rnd.choice([jmena_m, jmena_f][pohlavi])
prijmeni = rnd.choice([prijmeni_m, prijmeni_f][pohlavi])
Resitel.objects.create(skola = skola, datum_prihlaseni = datetime.date(rnd.randint(2002, 2014), rnd.randint(1,12), 1),
jmeno =jmeno, prijmeni = prijmeni, rok_maturity = rnd.randint(2015, 2019),
stat = skola.stat, zasilat = Resitel.ZASILAT_NIKAM, pohlavi_muz = pohlavi)
resitele = list(Resitel.objects.all())
# rocniky
last_rocnik = 21
for ri in range(last_rocnik - size, last_rocnik + 1):
r = Rocnik.objects.create(prvni_rok = 1993 + ri, rocnik = ri)
# cisla
cisel = rnd.randint(4, 6)
cs = {}
for ci in range(1, cisel + 1):
vydano = datetime.date(r.prvni_rok, ci + 6, 1)
deadline = datetime.date(r.prvni_rok, ci + 8, 1) if ci + 2 < cisel else None
c = Cislo.objects.create(rocnik = r, cislo = str(ci), datum_vydani=vydano, datum_deadline=deadline, verejne_db=True)
cs[ci] = c
# problemy resene v ci
seq='#ABCDEFGHIJKLMNOPQRSTUVWXYZ'
if ci >= 3:
for pi in range(1, ((size + 1) // 2) + 1):
p = Problem.objects.create(autor = rnd.choice(orgs), cislo_zadani=cs[ci-2], cislo_reseni=cs[ci],
opravovatel = rnd.choice(orgs), kod = str(pi), nazev = u'Dummy úloha %s-%s' % (seq[ci], seq[pi]),
stav = Problem.STAV_ZADANY, typ = Problem.TYP_ULOHA, body = rnd.randint(1, 5))
p.text_problemu = (u"<p>Text problému <strong>%s.%s %s</strong><em> [id %d]</em> za %d body.</p>" %
(p.cislo_zadani.kod(), p.kod, p.nazev, p.id, p.body))
p.text_problemu_org = u"<p><strong>Neveřejný</strong> text problému.</p>"
p.save()
poc_reseni = rnd.randint(size // 2, size * 2)
res_sel = rnd.sample(resitele, min(poc_reseni, len(resitele) - 2))
for resitel in res_sel:
res = Reseni.objects.create(problem = p, resitel = resitel,
body = rnd.randint(0, p.body), cislo_body = cs[ci])
sous = Soustredeni.objects.create(rocnik=Rocnik.objects.first(), verejne_db=True, misto=u'Někde',
datum_zacatku=datetime.date(2000, 11, 23), datum_konce=datetime.date(2000, 11, 27))
for res in rnd.sample(resitele, 6):
Soustredeni_Ucastnici.objects.create(resitel=res, soustredeni=sous)
sous.save()
nastaveni = Nastaveni.objects.create(aktualni_rocnik = Rocnik.objects.last(),
aktualni_cislo = Cislo.objects.all()[1])