[main]
name = "Settings"
[main.djfritz_config]
name = "django-fritzconnection configuration"
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"
Now i get this:
root@testyunohost:/home/jens# yunohost app config get django-fritzconnection
Fehler: Config panel question 'django_debug' should be initialized with a value during install or upgrade.
The generated local_settings.py looks fine:
root@testyunohost:/home/jens# cat /opt/yunohost/django-fritzconnection/local_settings.py
"""
Here it's possible to overwrite everything in settings.py
Note:
Used for YunoHost config and will be **overwritten** on every config change!
"""
DEBUG = False # Don't turn DEBUG on in production!
root@testyunohost:/home/jens# yunohost app config get django-fritzconnection
Fehler: Config panel question 'django_debug' should be initialized with a value during install or upgrade.
But ynh_add_config --template="local_settings.py" --destination="$final_path/local_settings.py" creates a correct file by replacing DEBUG = __DJANGO_DEBUG__ with DEBUG = False
I’m a little confused about the values for a boolean…
Internally YunoHost stores “0” and “1” so ynh_app_setting_set must be feeded with “0” / “1” but ynh_add_config will convert them to yes/no values if defined in config_panel.toml ?!?
And if not?
Is there some documentation about boolean handling, somewhere?!?
So the “yes/no” values in config_panel.toml are ignored?!?
But i still get the same error:
root@testyunohost:/home/jens# yunohost app config get django-fritzconnection
Fehler: Config panel question 'django_debug' should be initialized with a value during install or upgrade.
So the value is set and the error seems to be wrong:
root@testyunohost:/home/jens# yunohost app config get django-fritzconnection
Fehler: Config panel question 'django_debug' should be initialized with a value during install or upgrade.
As far as I understood the config panels, the bind function will parse local_settings.py looking for the DJANGO_DEBUG variable declaration line. However, the current file only contains DEBUG = False # Don't turn DEBUG on in production!
If you replace the config panel line by bind = "DEBUG:/opt/yunohost/__APP__/local_settings.py", it will find the right line but output ERROR Pick a valid value for argument 'django_debug': 'false # don't turn debug on in production!' is not among the available choices (yes/no).
Do not put comments on the same line
To avoid parsing issues, put # don't turn debug on in production!) on another line in local_settings.py.
…
Profit.
N.B. It seems it sets the True and False values as strings. I do not know if Django accepts that. If needed, you will need to write your own getter/setter or propose a core change to fix that.
Looks like a small PEBCAK and a strong “we really need proper documentation on that”.
Reference: YunoHost/yunohost#987
version = "1.0"
[main]
name = "django_example_ynh configuration"
services = ["__APP__"]
[main.config]
name = "Configuration Options"
[main.config.debug_enabled]
ask = "Enable DEBUG mode"
type = "boolean"
yes = "1"
no = "0"
help = "Should be never enabled in production!"
bind = "debug_enabled:__FINALPATH__/settings.py"
and conf/settings.py looks like:
# Set via config_panel.toml
DEBUG_ENABLED = '__DEBUG_ENABLED__'
DEBUG = bool(int(DEBUG_ENABLED))
Now I understand that it is important to name the variable DEBUG_ENABLED exactly like the name in the placeholder '__DEBUG_ENABLED__'
This DEBUG = bool(int(DEBUG_ENABLED)) looks a little bit strange, but the goals are:
The script is has no syntax error, even if the replacement was not done
int() will crash (“fail fast”) if replacement was not done
"1" and "0" are a better choices as the strings "true" and "false", because second ones looks so similar to the real True and False objects