Skip to content

Commit 83acfaa

Browse files
committed
go back to snapshotting Django's debug value
1 parent 9131a4a commit 83acfaa

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/reactpy_django/clean.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ def clean_sessions(verbosity: int = 1):
4949
"""Deletes expired component sessions from the database.
5050
As a performance optimization, this is only run once every REACTPY_SESSION_MAX_AGE seconds.
5151
"""
52-
from django.conf import settings as django_settings
5352

54-
from reactpy_django.config import REACTPY_SESSION_MAX_AGE
53+
from reactpy_django.config import DJANGO_DEBUG, REACTPY_SESSION_MAX_AGE
5554
from reactpy_django.models import ComponentSession
5655

5756
if verbosity >= 2:
@@ -68,7 +67,7 @@ def clean_sessions(verbosity: int = 1):
6867

6968
session_objects.delete()
7069

71-
if django_settings.DEBUG or verbosity >= 2:
70+
if DJANGO_DEBUG or verbosity >= 2:
7271
inspect_clean_duration(start_time, "component sessions", verbosity)
7372

7473

@@ -80,8 +79,7 @@ def clean_user_data(verbosity: int = 1):
8079
However, we can't use Django to enforce this relationship since ReactPy can be configured to
8180
use any database.
8281
"""
83-
from django.conf import settings as django_settings
84-
82+
from reactpy_django.config import DJANGO_DEBUG
8583
from reactpy_django.models import UserDataModel
8684

8785
if verbosity >= 2:
@@ -105,7 +103,7 @@ def clean_user_data(verbosity: int = 1):
105103

106104
user_data_objects.delete()
107105

108-
if django_settings.DEBUG or verbosity >= 2:
106+
if DJANGO_DEBUG or verbosity >= 2:
109107
inspect_clean_duration(start_time, "user data", verbosity)
110108

111109

src/reactpy_django/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
REACTPY_REGISTERED_IFRAME_VIEWS: dict[str, Callable | View] = {}
2424

2525
# Configurable through Django settings.py
26+
DJANGO_DEBUG = settings.DEBUG # Snapshot of Django's DEBUG setting
2627
_REACTPY_DEBUG_MODE.set_current(settings.DEBUG)
2728
_REACTPY_ASYNC_RENDERING.set_current(
2829
getattr(settings, "REACTPY_ASYNC_RENDERING", _REACTPY_ASYNC_RENDERING.current)

src/reactpy_django/templatetags/reactpy.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def component(
7474
</body>
7575
</html>
7676
"""
77-
from django.conf import settings as django_settings
77+
from reactpy_django.config import DJANGO_DEBUG
7878

7979
request: HttpRequest | None = context.get("request")
8080
perceived_host = (request.get_host() if request else "").strip("/")
@@ -95,7 +95,7 @@ def component(
9595
_offline_html = ""
9696

9797
# Validate the host
98-
if host and django_settings.DEBUG:
98+
if host and DJANGO_DEBUG:
9999
try:
100100
validate_host(host)
101101
except InvalidHostError as e:
@@ -110,7 +110,7 @@ def component(
110110
return failure_context(dotted_path, ComponentDoesNotExistError(msg))
111111

112112
# Validate the component args & kwargs
113-
if is_local and django_settings.DEBUG:
113+
if is_local and DJANGO_DEBUG:
114114
try:
115115
validate_component_args(user_component, *args, **kwargs)
116116
except ComponentParamError as e:
@@ -236,21 +236,21 @@ def pyscript_setup(
236236
config: A JSON string or Python dictionary containing PyScript \
237237
configuration values.
238238
"""
239-
from django.conf import settings as django_settings
239+
from reactpy_django.config import DJANGO_DEBUG
240240

241241
return {
242242
"pyscript_config": extend_pyscript_config(extra_py, extra_js, config),
243243
"pyscript_layout_handler": PYSCRIPT_LAYOUT_HANDLER,
244-
"django_debug": django_settings.DEBUG,
244+
"django_debug": DJANGO_DEBUG,
245245
}
246246

247247

248248
def failure_context(dotted_path: str, error: Exception):
249-
from django.conf import settings as django_settings
249+
from reactpy_django.config import DJANGO_DEBUG
250250

251251
return {
252252
"reactpy_failure": True,
253-
"django_debug": django_settings.DEBUG,
253+
"django_debug": DJANGO_DEBUG,
254254
"reactpy_dotted_path": dotted_path,
255255
"reactpy_error": type(error).__name__,
256256
}

0 commit comments

Comments
 (0)