1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00

feat(settings): WEBVIRTCLOUD_DEBUG=1 turns on Django's debug mode

DEBUG was fixed to False in the template, and Docker builds settings.py
from it in each container: debug mode could only be had by editing the
file inside a running container. It is now read from the environment like
the other options; off unless the variable is 1.

The toolbar's URLs follow settings-dev, which installs the toolbar, not
DEBUG: with the dev packages present, DEBUG alone imported them without
the app and every URL lookup failed.
This commit is contained in:
catborise 2026-11-09 09:05:38 +03:00
parent aead17dc32
commit a8fce405b3
4 changed files with 18 additions and 10 deletions

View file

@ -26,7 +26,8 @@ if not SECRET_KEY:
except OSError:
pass
DEBUG = False
# WEBVIRTCLOUD_DEBUG=1 shows error details on the pages: for trying things out only
DEBUG = os.getenv("WEBVIRTCLOUD_DEBUG") == "1"
MAC_OUI = '52:54:10'

View file

@ -12,7 +12,7 @@ from django.test import SimpleTestCase, TestCase, override_settings
# Env vars that change the settings; removed from the inherited environment so
# every case starts from the defaults.
CONFIG_VARS = [
"WEBVIRTCLOUD_HTTPS", "ALLOWED_HOSTS",
"WEBVIRTCLOUD_HTTPS", "WEBVIRTCLOUD_DEBUG", "ALLOWED_HOSTS",
"EMAIL_HOST", "EMAIL_PORT", "EMAIL_HOST_USER", "EMAIL_HOST_PASSWORD", "EMAIL_USE_TLS",
"WEBVIRTCLOUD_DB_HOST", "WEBVIRTCLOUD_DB_PORT", "WEBVIRTCLOUD_DB_NAME",
"WEBVIRTCLOUD_DB_USER", "WEBVIRTCLOUD_DB_PASSWORD",
@ -132,3 +132,13 @@ class DatabaseEnvTestCase(SimpleTestCase):
{"ENGINE": "django.db.backends.postgresql", "PORT": "5432",
"NAME": "webvirtcloud", "USER": "webvirtcloud", "PASSWORD": ""},
)
class DebugEnvTestCase(SimpleTestCase):
def test_debug_is_off_unless_asked(self):
self.assertFalse(load_settings({}, ["DEBUG"])["DEBUG"])
self.assertFalse(load_settings({"WEBVIRTCLOUD_DEBUG": "0"}, ["DEBUG"])["DEBUG"])
self.assertTrue(load_settings({"WEBVIRTCLOUD_DEBUG": "1"}, ["DEBUG"])["DEBUG"])
def test_debug_loads_the_urls(self):
run_manage({"WEBVIRTCLOUD_DEBUG": "1"}, "check")

View file

@ -43,13 +43,9 @@ urlpatterns = [
re_path(r"^api/(?:.*/)?$", api_not_found),
]
if settings.DEBUG:
try:
import debug_toolbar
# settings-dev installs the toolbar; WEBVIRTCLOUD_DEBUG alone does not
if "debug_toolbar" in settings.INSTALLED_APPS:
import debug_toolbar
urlpatterns += [
path("__debug__/", include(debug_toolbar.urls)),
]
except ImportError:
pass
urlpatterns += [path("__debug__/", include(debug_toolbar.urls))]