Skip to content

Commit a22efb5

Browse files
committed
Remove reactpy_django.config.REACTPY_DEBUG_MODE
1 parent 3d46f36 commit a22efb5

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

src/reactpy_django/clean.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ 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 reactpy_django.config import REACTPY_DEBUG_MODE, REACTPY_SESSION_MAX_AGE
52+
from django.conf import settings as django_settings
53+
54+
from reactpy_django.config import REACTPY_SESSION_MAX_AGE
5355
from reactpy_django.models import ComponentSession
5456

5557
if verbosity >= 2:
@@ -66,7 +68,7 @@ def clean_sessions(verbosity: int = 1):
6668

6769
session_objects.delete()
6870

69-
if REACTPY_DEBUG_MODE or verbosity >= 2:
71+
if django_settings.DEBUG or verbosity >= 2:
7072
inspect_clean_duration(start_time, "component sessions", verbosity)
7173

7274

@@ -78,7 +80,8 @@ def clean_user_data(verbosity: int = 1):
7880
However, we can't use Django to enforce this relationship since ReactPy can be configured to
7981
use any database.
8082
"""
81-
from reactpy_django.config import REACTPY_DEBUG_MODE
83+
from django.conf import settings as django_settings
84+
8285
from reactpy_django.models import UserDataModel
8386

8487
if verbosity >= 2:
@@ -102,7 +105,7 @@ def clean_user_data(verbosity: int = 1):
102105

103106
user_data_objects.delete()
104107

105-
if REACTPY_DEBUG_MODE or verbosity >= 2:
108+
if django_settings.DEBUG or verbosity >= 2:
106109
inspect_clean_duration(start_time, "user data", verbosity)
107110

108111

src/reactpy_django/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
from reactpy_django.utils import import_dotted_path
1919

2020
# Non-configurable values
21-
REACTPY_DEBUG_MODE = _REACTPY_DEBUG_MODE.current
2221
REACTPY_REGISTERED_COMPONENTS: dict[str, ComponentConstructor] = {}
2322
REACTPY_FAILED_COMPONENTS: set[str] = set()
2423
REACTPY_REGISTERED_IFRAME_VIEWS: dict[str, Callable | View] = {}
2524

2625
# Configurable through Django settings.py
27-
_REACTPY_DEBUG_MODE.set_current(getattr(settings, "DEBUG"))
26+
_REACTPY_DEBUG_MODE.set_current(settings.DEBUG)
2827
_REACTPY_ASYNC_RENDERING.set_current(
2928
getattr(settings, "REACTPY_ASYNC_RENDERING", _REACTPY_ASYNC_RENDERING.current)
3029
)
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% load static %}
22

3-
{% if reactpy_failure and reactpy_debug_mode %}
3+
{% if reactpy_failure and debug %}
44
<pre>{% firstof reactpy_error "UnknownError" %}: "{% firstof reactpy_dotted_path "UnknownPath" %}"</pre>
55
{% endif %}
66

@@ -10,18 +10,18 @@
1010
{% if reactpy_prerender_html %}<div id="{{reactpy_uuid}}-prerender">{{reactpy_prerender_html|safe}}</div>{% endif %}
1111
{% if reactpy_offline_html %}<div id="{{reactpy_uuid}}-offline" hidden>{{reactpy_offline_html|safe}}</div>{% endif %}
1212
<script type="module" crossorigin="anonymous">
13-
import { mountComponent } from "{% static 'reactpy_django/client.js' %}";
14-
const mountElement = document.getElementById("{{reactpy_uuid}}");
15-
mountComponent(
16-
mountElement,
17-
"{{reactpy_host}}",
18-
"{{reactpy_url_prefix}}",
19-
"{{reactpy_component_path}}",
20-
"{{reactpy_resolved_web_modules_path}}",
21-
Number("{{reactpy_reconnect_interval}}"),
22-
Number("{{reactpy_reconnect_max_interval}}"),
23-
Number("{{reactpy_reconnect_max_retries}}"),
24-
Number("{{reactpy_reconnect_backoff_multiplier}}"),
25-
);
13+
import { mountComponent } from "{% static 'reactpy_django/client.js' %}";
14+
const mountElement = document.getElementById("{{reactpy_uuid}}");
15+
mountComponent(
16+
mountElement,
17+
"{{reactpy_host}}",
18+
"{{reactpy_url_prefix}}",
19+
"{{reactpy_component_path}}",
20+
"{{reactpy_resolved_web_modules_path}}",
21+
Number("{{reactpy_reconnect_interval}}"),
22+
Number("{{reactpy_reconnect_max_interval}}"),
23+
Number("{{reactpy_reconnect_max_retries}}"),
24+
Number("{{reactpy_reconnect_backoff_multiplier}}"),
25+
);
2626
</script>
2727
{% endif %}

src/reactpy_django/templates/reactpy/pyscript_setup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% load static %}
22
<link rel="stylesheet" href="{% static 'reactpy_django/pyscript/core.css' %}" />
33
<link rel="stylesheet" href="{% static 'reactpy_django/pyscript-custom.css' %}" />
4-
{% if not reactpy_debug_mode %}
4+
{% if not debug %}
55
<link rel="stylesheet" href="{% static 'reactpy_django/pyscript-hide-debug.css' %}" />
66
{% endif %}
77
<script type="module" async crossorigin="anonymous" src="{% static 'reactpy_django/pyscript/core.js' %}"></script>

src/reactpy_django/templatetags/reactpy.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def component(
7474
</body>
7575
</html>
7676
"""
77+
from django.conf import settings as django_settings
78+
7779
request: HttpRequest | None = context.get("request")
7880
perceived_host = (request.get_host() if request else "").strip("/")
7981
host = (
@@ -93,7 +95,7 @@ def component(
9395
_offline_html = ""
9496

9597
# Validate the host
96-
if host and reactpy_config.REACTPY_DEBUG_MODE:
98+
if host and django_settings.DEBUG:
9799
try:
98100
validate_host(host)
99101
except InvalidHostError as e:
@@ -108,7 +110,7 @@ def component(
108110
return failure_context(dotted_path, ComponentDoesNotExistError(msg))
109111

110112
# Validate the component args & kwargs
111-
if is_local and reactpy_config.REACTPY_DEBUG_MODE:
113+
if is_local and django_settings.DEBUG:
112114
try:
113115
validate_component_args(user_component, *args, **kwargs)
114116
except ComponentParamError as e:
@@ -234,17 +236,21 @@ def pyscript_setup(
234236
config: A JSON string or Python dictionary containing PyScript \
235237
configuration values.
236238
"""
239+
from django.conf import settings as django_settings
240+
237241
return {
238242
"pyscript_config": extend_pyscript_config(extra_py, extra_js, config),
239243
"pyscript_layout_handler": PYSCRIPT_LAYOUT_HANDLER,
240-
"reactpy_debug_mode": reactpy_config.REACTPY_DEBUG_MODE,
244+
"debug": django_settings.DEBUG,
241245
}
242246

243247

244248
def failure_context(dotted_path: str, error: Exception):
249+
from django.conf import settings as django_settings
250+
245251
return {
246252
"reactpy_failure": True,
247-
"reactpy_debug_mode": reactpy_config.REACTPY_DEBUG_MODE,
253+
"debug": django_settings.DEBUG,
248254
"reactpy_dotted_path": dotted_path,
249255
"reactpy_error": type(error).__name__,
250256
}

0 commit comments

Comments
 (0)