2015-03-14 17:24:18 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
|
2019-05-10 23:59:15 +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()
|
|
|
|
|
|
|
|
|
2019-05-10 23:59:15 +02:00
|
|
|
class Command(BaseCommand):
|
2019-08-14 01:45:06 +02:00
|
|
|
help = "Clear database and load testing data."
|
|
|
|
|
2019-08-14 02:06:31 +02:00
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument(
|
|
|
|
'--no-clean',
|
|
|
|
action='store_true',
|
|
|
|
help='Změny se provedou v aktuální DB, ne v čisté. Aktuální DB se nezachová. (jen k debugování)',
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
'--no-migrate',
|
|
|
|
action='store_true',
|
|
|
|
help='Neprovádět migrace před generováním testovacích dat (jen k debugování)',
|
|
|
|
)
|
|
|
|
|
2019-08-14 01:45:06 +02:00
|
|
|
def handle(self, *args, **options):
|
|
|
|
assert settings.DEBUG == True
|
|
|
|
dbfile = settings.DATABASES['default']['NAME']
|
2019-08-14 02:06:31 +02:00
|
|
|
if os.path.exists(dbfile) and not options['no_clean']:
|
2019-08-14 01:45:06 +02:00
|
|
|
os.rename(dbfile, dbfile + '.old')
|
|
|
|
self.stderr.write('Stara databaze prejmenovana na "%s"' % (dbfile + '.old'))
|
2019-08-14 02:06:31 +02:00
|
|
|
if not options['no_migrate']:
|
|
|
|
call_command('migrate', no_input=True)
|
2019-08-14 01:45:06 +02:00
|
|
|
self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...')
|
2020-02-11 23:07:45 +01:00
|
|
|
create_test_data(size=5)
|
|
|
|
# menší počet ročníků, aby se zrychlilo generování dat a bylo dost úloh
|
2019-08-14 01:45:06 +02:00
|
|
|
self.stdout.write('Vytvoreno {} uzivatelu, {} skol, {} resitelu, {} rocniku, {} cisel,'
|
|
|
|
' {} problemu, {} reseni.'.format(User.objects.count(), Skola.objects.count(),
|
|
|
|
Resitel.objects.count(), Rocnik.objects.count(), Cislo.objects.count(),
|
|
|
|
Problem.objects.count(), Reseni.objects.count()))
|
2015-03-14 22:27:04 +01:00
|
|
|
|
|
|
|
|
2015-03-14 17:24:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|