26 lines
852 B
Python
Raw Normal View History

"""
reinitialize the test user account (and clean up)
"""
from django.conf import settings
2013-11-24 09:37:47 +01:00
from django.contrib.auth import get_user_model
from django.core.management.base import NoArgsCommand
class Command(NoArgsCommand):
help = 'reinitialize the test user'
def handle_noargs(self, **options):
2013-11-24 09:37:47 +01:00
user_model = get_user_model()
try:
2013-11-24 09:37:47 +01:00
u = user_model.objects.get(username='test')
# delete test user and (via CASCADE behaviour) everything that
# points to it (has user as ForeignKey), e.g. via created_by.
u.delete()
2013-11-24 09:37:47 +01:00
except user_model.DoesNotExist:
pass
# create a fresh test user
2013-11-24 09:37:47 +01:00
u = user_model.objects.create_user('test', settings.DEFAULT_FROM_EMAIL, 'test')
u.save()
self.stdout.write('Successfully reinitialized the test user')