From 4ea25646c7d2606f1261bc537be5d1b1ad047ca9 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 18 May 2022 18:11:49 +0200 Subject: [PATCH] Add config to change settings.DEBUG --- conf/local_settings.py | 8 ++++++++ conf/settings.py | 3 +-- config_panel.toml | 20 ++++++++++++++++++++ manifest.json | 4 ++-- scripts/_common.sh | 3 +++ scripts/install | 5 ++++- scripts/restore | 2 -- scripts/upgrade | 13 ++++++++++++- 8 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 conf/local_settings.py create mode 100644 config_panel.toml diff --git a/conf/local_settings.py b/conf/local_settings.py new file mode 100644 index 0000000..6e3b208 --- /dev/null +++ b/conf/local_settings.py @@ -0,0 +1,8 @@ +""" + Here it's possible to overwrite everything in settings.py + + Note: + Used for YunoHost config and will be **overwritten** on every config change! +""" + +DEBUG = __DJANGO_DEBUG__ # Don't turn DEBUG on in production! diff --git a/conf/settings.py b/conf/settings.py index af40036..9a3ed36 100644 --- a/conf/settings.py +++ b/conf/settings.py @@ -13,11 +13,10 @@ from pathlib import Path as __Path from django_yunohost_integration.base_settings import * # noqa from django_yunohost_integration.secret_key import get_or_create_secret as __get_or_create_secret + from djfritz_project.settings.base import * # noqa -DEBUG = False # Don't turn DEBUG on in production! - # ----------------------------------------------------------------------------- FINAL_HOME_PATH = __Path('__FINAL_HOME_PATH__') # /opt/yunohost/$app diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 0000000..a56e6e4 --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,20 @@ +# https://github.com/YunoHost/example_ynh/blob/master/config_panel.toml.example + +version = "1.0" + +[main] +name = "Settings" + + [main.djfritz_config] + name = "django-fritzconnection configuration" + + # Trigger a service reload-or-restart after the user change a question in this panel + services = ["__APP__"] + + [main.djfritz_config.django_debug] + ask = "debug mode" + help = "Important: Never activate this settings.DEBUG on production!" + type = "boolean" + yes = "True" + no = "False" + bind = "DJANGO_DEBUG:/opt/yunohost/__APP__/local_settings.py" diff --git a/manifest.json b/manifest.json index c0ebbf0..de1a96a 100644 --- a/manifest.json +++ b/manifest.json @@ -19,7 +19,7 @@ }, "previous_maintainers": [], "requirements": { - "yunohost": ">= 4.0" + "yunohost": ">= 4.3.0" }, "multi_instance": true, "services": [ @@ -41,6 +41,6 @@ "name": "admin", "type": "user" } - ] + ] } } diff --git a/scripts/_common.sh b/scripts/_common.sh index 48b61a1..4c670f0 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -22,6 +22,9 @@ final_path=/opt/yunohost/$app log_path=/var/log/$app log_file="${log_path}/django-fritzconnection.log" +# Default: settings.DEBUG=False +django_debug="False" + #================================================= # COMMON VARIABLES #================================================= diff --git a/scripts/install b/scripts/install index f785a50..7550d58 100755 --- a/scripts/install +++ b/scripts/install @@ -57,6 +57,9 @@ db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd) admin_mail=$(ynh_user_get_info --username="$admin" --key=mail) redis_db=$(ynh_redis_get_free_db) +# Always deactivate settings.DEBUG: +ynh_app_setting_set --app=$app --key=django_debug --value="0" + #================================================= # STANDARD MODIFICATIONS #================================================= @@ -164,7 +167,7 @@ cp ../conf/setup_user.py "$final_path/setup_user.py" cp ../conf/urls.py "$final_path/urls.py" cp ../conf/wsgi.py "$final_path/wsgi.py" -touch "$final_path/local_settings.py" +ynh_add_config --template="local_settings.py" --destination="$final_path/local_settings.py" #================================================= # MIGRATE / COLLECTSTATIC / CREATEADMIN diff --git a/scripts/restore b/scripts/restore index 0cbf548..43fa5f8 100755 --- a/scripts/restore +++ b/scripts/restore @@ -55,8 +55,6 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$public_path" ynh_restore_file --origin_path="$final_path" -touch "$final_path/local_settings.py" - #================================================= # RECREATE THE DEDICATED USER #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 09a1963..92193f9 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -29,6 +29,8 @@ db_user=$db_name admin_mail=$(ynh_user_get_info "$admin" mail) redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db) +django_debug=$(ynh_app_setting_get --app="$app" --key=django_debug) + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -52,6 +54,13 @@ ynh_script_progression --message="Stopping systemd services..." --weight=5 ynh_systemd_action --service_name="$app" --action="stop" +#================================================= +# Manage old settings +#================================================= + +# Always deactivate settings.DEBUG: +ynh_app_setting_set --app=$app --key=django_debug --value="0" + #================================================= # NGINX CONFIGURATION #================================================= @@ -159,7 +168,9 @@ cp ../conf/urls.py "$final_path/urls.py" ynh_backup_if_checksum_is_different --file="$final_path/wsgi.py" cp ../conf/wsgi.py "$final_path/wsgi.py" -touch "$final_path/local_settings.py" +# Regenerate a fresh local_settings: +ynh_backup_if_checksum_is_different --file="$final_path/local_settings.py" +ynh_add_config --template="local_settings.py" --destination="$final_path/local_settings.py" #================================================= # MIGRATE PYINVENTORY