|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
|
|
|
|
from django.core.management.base import NoArgsCommand
|
|
|
|
from django.core.management import call_command
|
|
|
|
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):
|
|
|
|
help = "Clear database and load testing data."
|
|
|
|
|
|
|
|
def handle_noargs(self, **options):
|
|
|
|
assert settings.DEBUG == True
|
|
|
|
dbfile = settings.DATABASES['default']['NAME']
|
|
|
|
if os.path.exists(dbfile):
|
|
|
|
os.rename(dbfile, dbfile + '.old')
|
|
|
|
self.stderr.write('Stara databaze prejmenovana na "%s"' % (dbfile + '.old'))
|
|
|
|
call_command('migrate', noinput=True)
|
|
|
|
self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...')
|
|
|
|
create_test_data()
|
|
|
|
self.stdout.write('Vytvoreno %d uzivatelu, %d skol, %d resitelu, %d rocniku, %d cisel, %d problemu, %d reseni.' %
|
|
|
|
(User.objects.count(), Skola.objects.count(), Resitel.objects.count(), Rocnik.objects.count(),
|
|
|
|
Cislo.objects.count(), Problem.objects.count(), Reseni.objects.count()))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|