|
@ -17,12 +17,25 @@ User = django.contrib.auth.get_user_model() |
|
|
class Command(BaseCommand): |
|
|
class Command(BaseCommand): |
|
|
help = "Clear database and load testing data." |
|
|
help = "Clear database and load testing data." |
|
|
|
|
|
|
|
|
|
|
|
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í)', |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
def handle(self, *args, **options): |
|
|
def handle(self, *args, **options): |
|
|
assert settings.DEBUG == True |
|
|
assert settings.DEBUG == True |
|
|
dbfile = settings.DATABASES['default']['NAME'] |
|
|
dbfile = settings.DATABASES['default']['NAME'] |
|
|
if os.path.exists(dbfile): |
|
|
if os.path.exists(dbfile) and not options['no_clean']: |
|
|
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')) |
|
|
|
|
|
if not options['no_migrate']: |
|
|
call_command('migrate', no_input=True) |
|
|
call_command('migrate', no_input=True) |
|
|
self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...') |
|
|
self.stdout.write('Vytvarim uzivatele "admin" (heslo "admin") a pseudo-nahodna data ...') |
|
|
create_test_data(size=8) |
|
|
create_test_data(size=8) |
|
|