|
@ -8,6 +8,12 @@ from django.core.management.base import NoArgsCommand |
|
|
from django.core.management import call_command |
|
|
from django.core.management import call_command |
|
|
from django.conf import settings |
|
|
from django.conf import settings |
|
|
|
|
|
|
|
|
|
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni |
|
|
|
|
|
from seminar.tests import create_test_data |
|
|
|
|
|
import django.contrib.auth |
|
|
|
|
|
User = django.contrib.auth.get_user_model() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Command(NoArgsCommand): |
|
|
class Command(NoArgsCommand): |
|
|
help = "Clear database and load testing data." |
|
|
help = "Clear database and load testing data." |
|
|
|
|
|
|
|
@ -18,76 +24,13 @@ class Command(NoArgsCommand): |
|
|
os.rename(dbfile, dbfile + '.old') |
|
|
os.rename(dbfile, dbfile + '.old') |
|
|
self.stderr.write('Stara databaze prejmenovana na "%s"' % (dbfile + '.old')) |
|
|
self.stderr.write('Stara databaze prejmenovana na "%s"' % (dbfile + '.old')) |
|
|
call_command('migrate', noinput=True) |
|
|
call_command('migrate', noinput=True) |
|
|
self.load_testing_data() |
|
|
self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...') |
|
|
|
|
|
create_test_data() |
|
|
def load_testing_data(self): |
|
|
self.stdout.write('Vytvoreno %d uzivatelu, %d skol, %d resitelu, %d rocniku, %d cisel, %d problemu, %d reseni.' % |
|
|
from seminar import models as sm |
|
|
(User.objects.count(), Skola.objects.count(), Resitel.objects.count(), Rocnik.objects.count(), |
|
|
import django.contrib.auth |
|
|
Cislo.objects.count(), Problem.objects.count(), Reseni.objects.count())) |
|
|
User = django.contrib.auth.get_user_model() |
|
|
|
|
|
|
|
|
|
|
|
self.stderr.write('Vytvarim uzivatele "admin" (heslo "admin")') |
|
|
|
|
|
|
|
|
|
|
|
# pevna pseudo-nahodnost |
|
|
|
|
|
rnd = random.Random(x=42) |
|
|
|
|
|
|
|
|
|
|
|
# users |
|
|
|
|
|
admin = User.objects.create_superuser(username='admin', email='', password='admin') |
|
|
|
|
|
|
|
|
|
|
|
self.stderr.write('Vytvarim pseudo-nahodna data') |
|
|
|
|
|
|
|
|
|
|
|
orgs = [] |
|
|
|
|
|
for org in ['anet', 'bara', 'cyril', 'david', 'eva', 'filip']: |
|
|
|
|
|
o = User.objects.create_user(username=org, password=org) |
|
|
|
|
|
o.first_name = org.capitalize() |
|
|
|
|
|
o.save() |
|
|
|
|
|
orgs.append(o) |
|
|
|
|
|
|
|
|
|
|
|
# skoly |
|
|
|
|
|
sm.Skola.objects.create(mesto = u'Praha', stat='CZ', psc='101 00', ulice=u'Krátká 5', nazev=u'První SŠ') |
|
|
|
|
|
sm.Skola.objects.create(mesto = u'Praha', stat='CZ', psc='102 00', ulice=u'Dlouhá 5', nazev=u'Druhá SŠ') |
|
|
|
|
|
sm.Skola.objects.create(mesto = u'Praha', stat='CZ', psc='103 00', ulice=u'Široká 3', nazev=u'Třetí SŠ') |
|
|
|
|
|
sm.Skola.objects.create(mesto = u'Ostrava', stat='CZ', psc='700 00', ulice=u'Hluboká 42', nazev=u'Hutní gympl') |
|
|
|
|
|
sm.Skola.objects.create(mesto = u'Humenné', stat='SK', psc='012 34', ulice=u'Pltká 1', nazev=u'Sredná škuola') |
|
|
|
|
|
|
|
|
|
|
|
# resitele |
|
|
|
|
|
for i in range(20): |
|
|
|
|
|
skola = rnd.choice(sm.Skola.objects.all()) |
|
|
|
|
|
pohlavi = rnd.randint(0,1) |
|
|
|
|
|
sm.Resitel.objects.create(skola = skola, datum_prihlaseni = datetime.date(rnd.randint(2002, 2014), rnd.randint(1,12), 1), |
|
|
|
|
|
jmeno = u'Řešitel' if pohlavi else u'Řešitelka', prijmeni = 'Číslo-%s' % (i), rok_maturity = rnd.randint(2015, 2019), |
|
|
|
|
|
stat = skola.stat, zasilat = sm.Resitel.ZASILAT_NIKAM, pohlavi_muz = pohlavi) |
|
|
|
|
|
|
|
|
|
|
|
# rocniky |
|
|
|
|
|
for ri in range(17, 22): |
|
|
|
|
|
r = sm.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 = sm.Cislo.objects.create(rocnik = r, cislo = str(ci), datum_vydani=vydano, datum_deadline=deadline) |
|
|
|
|
|
cs[ci] = c |
|
|
|
|
|
|
|
|
|
|
|
# problemy resene v ci |
|
|
|
|
|
seq='#ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
|
|
|
|
if ci >= 3: |
|
|
|
|
|
for pi in range(1, 4): |
|
|
|
|
|
p = sm.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 = sm.Problem.STAV_ZADANY, typ = sm.Problem.TYP_ULOHA, body = rnd.randint(1, 5)) |
|
|
|
|
|
|
|
|
|
|
|
for resi in range(rnd.randint(0, 7)): |
|
|
|
|
|
res = sm.Reseni.objects.create(problem = p, resitel = rnd.choice(sm.Resitel.objects.all()), |
|
|
|
|
|
body = rnd.randint(0, p.body), cislo_body = cs[ci]) |
|
|
|
|
|
|
|
|
|
|
|
nastaveni = sm.Nastaveni.objects.create(aktualni_rocnik = sm.Rocnik.objects.last(), |
|
|
|
|
|
aktualni_cislo = sm.Cislo.objects.last()) |
|
|
|
|
|
|
|
|
|
|
|
self.stderr.write('Vytvoreno %d uzivatelu, %d skol, %d resitelu, %d rocniku, %d cisel, %d problemu, %d reseni.' % |
|
|
|
|
|
(User.objects.count(), sm.Skola.objects.count(), sm.Resitel.objects.count(), sm.Rocnik.objects.count(), |
|
|
|
|
|
sm.Cislo.objects.count(), sm.Problem.objects.count(), sm.Reseni.objects.count())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|