2015-03-14 17:24:18 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
|
2018-09-17 00:01:16 +02:00
|
|
|
from django.core.management.base import BaseCommand
|
2015-03-14 17:24:18 +01:00
|
|
|
from django.core.management import call_command
|
|
|
|
from django.conf import settings
|
|
|
|
|
2015-03-14 22:27:04 +01:00
|
|
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni
|
2015-03-29 14:52:07 +02:00
|
|
|
from seminar.testutils import create_test_data
|
2015-03-14 22:27:04 +01:00
|
|
|
import django.contrib.auth
|
|
|
|
User = django.contrib.auth.get_user_model()
|
|
|
|
|
|
|
|
|
2018-09-17 00:01:16 +02:00
|
|
|
class Command(BaseCommand):
|
2015-03-14 17:24:18 +01:00
|
|
|
help = "Clear database and load testing data."
|
|
|
|
|
2018-09-17 00:10:00 +02:00
|
|
|
def handle(self, *args, **options):
|
2015-03-14 17:24:18 +01:00
|
|
|
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)
|
2015-03-14 22:27:04 +01:00
|
|
|
self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...')
|
2015-03-29 14:52:07 +02:00
|
|
|
create_test_data(size=8)
|
2015-03-14 22:27:04 +01:00
|
|
|
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()))
|
|
|
|
|
|
|
|
|
2015-03-14 17:24:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|