Web M&M
https://mam.matfyz.cz
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.
56 lines
1.7 KiB
56 lines
1.7 KiB
10 years ago
|
import datetime
|
||
|
import os
|
||
|
import random
|
||
|
|
||
6 years ago
|
from django.core.management.base import BaseCommand
|
||
10 years ago
|
from django.core.management import call_command
|
||
|
from django.conf import settings
|
||
|
|
||
10 years ago
|
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni
|
||
10 years ago
|
from seminar.testutils import create_test_data
|
||
10 years ago
|
import django.contrib.auth
|
||
|
User = django.contrib.auth.get_user_model()
|
||
|
|
||
|
|
||
6 years ago
|
class Command(BaseCommand):
|
||
5 years ago
|
help = "Clear database and load testing data."
|
||
|
|
||
5 years ago
|
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í)',
|
||
|
)
|
||
|
|
||
5 years ago
|
def handle(self, *args, **options):
|
||
|
assert settings.DEBUG == True
|
||
|
dbfile = settings.DATABASES['default']['NAME']
|
||
5 years ago
|
if os.path.exists(dbfile) and not options['no_clean']:
|
||
5 years ago
|
os.rename(dbfile, dbfile + '.old')
|
||
|
self.stderr.write('Stara databaze prejmenovana na "%s"' % (dbfile + '.old'))
|
||
5 years ago
|
if not options['no_migrate']:
|
||
|
call_command('migrate', no_input=True)
|
||
5 years ago
|
self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...')
|
||
5 years ago
|
create_test_data(size=5)
|
||
|
# menší počet ročníků, aby se zrychlilo generování dat a bylo dost úloh
|
||
5 years ago
|
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()))
|
||
10 years ago
|
|
||
|
|
||
10 years ago
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|