forked from totallylegitco/fighthealthinsurance
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add admin user and a replica for the serving side
- Loading branch information
Showing
4 changed files
with
52 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
fighthealthinsurance/management/commands/ensure_adminuser.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# See https://stackoverflow.com/questions/39744593/how-to-create-a-django-superuser-if-it-doesnt-exist-non-interactively | ||
# Covered by https://stackoverflow.com/help/licensing | ||
import os | ||
from django.contrib.auth import get_user_model | ||
from django.core.management.base import BaseCommand | ||
|
||
class Command(BaseCommand): | ||
help = "Creates an admin user non-interactively if it doesn't exist" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('--username', help="Admin's username") | ||
parser.add_argument('--email', help="Admin's email") | ||
parser.add_argument('--password', help="Admin's password") | ||
parser.add_argument('--no-input', help="Read options from the environment", | ||
action='store_true') | ||
|
||
def handle(self, *args, **options): | ||
User = get_user_model() | ||
|
||
if options['no_input']: | ||
options['username'] = os.environ['FIGHT_HEALTH_ADMIN_USER'] | ||
options['email'] = os.environ['FIGHT_HEALTH_ADMIN_USER'] | ||
options['password'] = os.environ['FIGHT_HEALTH_ADMIN_PASSWORD'] | ||
|
||
if not User.objects.filter(username=options['username']).exists(): | ||
User.objects.create_superuser(username=options['username'], | ||
email=options['email'], | ||
password=options['password']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters