Automatically create DJ user at initial migration.

This commit is contained in:
Josh Washburne 2017-12-28 10:10:39 -05:00
parent 0b0a0191f2
commit bf7b5061e9
3 changed files with 56 additions and 2 deletions

7
.gitignore vendored
View file

@ -9,7 +9,6 @@ __pycache__/
# Distribution / packaging # Distribution / packaging
.Python .Python
.venv/ .venv/
.env
build/ build/
develop-eggs/ develop-eggs/
dist/ dist/
@ -42,4 +41,8 @@ docs/_build/
# IDE customizations # IDE customizations
.vscode/ .vscode/
requirements-dev.txt requirements-dev.txt
# Sensitive information
.env
.djinfo

View file

@ -0,0 +1,39 @@
# Generated by Django 2.0 on 2017-12-27 21:22
import os
from django.conf import settings
from django.contrib.auth.hashers import make_password
from django.db import migrations, models
from core.utils import generate_password
def create_dj_user(apps, schema_editor):
User = apps.get_model('core', 'RadioUser')
db_alias = schema_editor.connection.alias
new_password = generate_password()
dj = User(email=settings.RADIO_DJ_EMAIL,
name=settings.RADIO_DJ_NAME,
password=make_password(new_password),
is_superuser=False,
is_staff=True,
is_dj=True)
dj.save(using=db_alias)
with open(os.path.join(settings.PROJECT_DIR, '.djinfo'), 'w') as f:
f.write('Email: {}\n'.format(dj.email))
f.write('Name: {}\n'.format(dj.name))
f.write('Password: {}\n'.format(new_password))
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
]
operations = [
migrations.RunPython(create_dj_user),
]

View file

@ -8,6 +8,10 @@ CONFIG_DIR = os.path.dirname(SETTINGS_DIR)
PROJECT_DIR = os.path.dirname(CONFIG_DIR) PROJECT_DIR = os.path.dirname(CONFIG_DIR)
BASE_DIR = os.path.dirname(PROJECT_DIR) BASE_DIR = os.path.dirname(PROJECT_DIR)
###
### Django-specific settings
###
AUTH_PASSWORD_VALIDATORS = [ AUTH_PASSWORD_VALIDATORS = [
{ {
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
@ -83,3 +87,11 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
WSGI_APPLICATION = 'savepointradio.wsgi.application' WSGI_APPLICATION = 'savepointradio.wsgi.application'
###
### Radio-specific settings
###
RADIO_DJ_EMAIL = config('RADIO_DJ_EMAIL', default='dj@radiostation.net')
RADIO_DJ_NAME = config('RADIO_DJ_NAME', default='DJ Reinhardt')