From c7c5aa877aba77ec84858dd0ec64689dbe9c7b0e Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sun, 17 Jan 2021 11:42:44 +0100 Subject: [PATCH] use "create_superuser" from "django_ynh" --- conf/create_superuser.py | 46 ---------------------------------------- scripts/install | 9 ++++---- scripts/upgrade | 10 ++++----- 3 files changed, 8 insertions(+), 57 deletions(-) delete mode 100644 conf/create_superuser.py diff --git a/conf/create_superuser.py b/conf/create_superuser.py deleted file mode 100644 index b6312d8..0000000 --- a/conf/create_superuser.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 -import argparse -import os -import sys - - -def main(): - os.environ['DJANGO_SETTINGS_MODULE'] = 'ynh_for_runners_settings' - - parser = argparse.ArgumentParser( - description='Create or update Django super user.' - ) - parser.add_argument('--username') - parser.add_argument('--email') - parser.add_argument('--password') - - args = parser.parse_args() - username = args.username - email = args.email or '' - password = args.password - - import django - django.setup() - - from django.contrib.auth import get_user_model - User = get_user_model() - user = User.objects.filter(username=username).first() - if user: - print('Update existing user and set his password.', file=sys.stderr) - user.is_active = True - user.is_staff = True - user.is_superuser = True - user.set_password(password) - user.email = email - user.save() - else: - print('Create new super user', file=sys.stderr) - User.objects.create_superuser( - username=username, - email=email, - password=password - ) - - -if __name__ == '__main__': - main() diff --git a/scripts/install b/scripts/install index 5a7ff0b..f3e14d8 100755 --- a/scripts/install +++ b/scripts/install @@ -120,10 +120,7 @@ chown -R "$app" "$final_path" #================================================= # copy config files # ================================================ -ynh_script_progression --message="Create django-for-runners configuration file..." - -cp ../conf/create_superuser.py "$final_path/create_superuser.py" -chmod +x "$final_path/create_superuser.py" +ynh_script_progression --message="Create project configuration files..." gunicorn_conf="$final_path/gunicorn.conf.py" cp "../conf/gunicorn.conf.py" "$gunicorn_conf" @@ -178,7 +175,9 @@ ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight ./manage.py migrate --no-input ./manage.py collectstatic --no-input - ./create_superuser.py --username="$admin" --email="$admin_mail" --password="django-for-runners" + + # Create/update Django superuser (set unusable password, because auth done via SSOwat): + ./manage.py create_superuser --username="$admin" --email="$admin_mail" # Check the configuration # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. diff --git a/scripts/upgrade b/scripts/upgrade index b9e5262..4d633dc 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -105,11 +105,7 @@ chown -R "$app" "$final_path" #================================================= # copy config files # ================================================ -ynh_script_progression --message="Create django-for-runners configuration file..." - -ynh_backup_if_checksum_is_different --file="$final_path/create_superuser.py" -cp ../conf/create_superuser.py "$final_path/create_superuser.py" -chmod +x "$final_path/create_superuser.py" +ynh_script_progression --message="Create project configuration files..." gunicorn_conf="$final_path/gunicorn.conf.py" ynh_backup_if_checksum_is_different --file="$gunicorn_conf" @@ -168,7 +164,9 @@ ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight ./manage.py migrate --no-input ./manage.py collectstatic --no-input - ./create_superuser.py --username="$admin" --email="$admin_mail" --password="django-for-runners" + + # Create/update Django superuser (set unusable password, because auth done via SSOwat): + ./manage.py create_superuser --username="$admin" --email="$admin_mail" # Check the configuration # This may fail in some cases with errors, etc., but the app works and the user can fix issues later.