Skip to content

Commit 9360e51

Browse files
committed
REACTPY_DEFAULT_FORM_TEMPLATE
1 parent 24ad84c commit 9360e51

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/reactpy_django/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,8 @@
126126
"REACTPY_CLEAN_USER_DATA",
127127
True,
128128
)
129+
REACTPY_DEFAULT_FORM_TEMPLATE: str | None = getattr(
130+
settings,
131+
"REACTPY_DEFAULT_FORM_TEMPLATE",
132+
None,
133+
)

src/reactpy_django/forms/components.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from django.forms import Form, ModelForm
99
from reactpy import component, hooks, html, utils
1010
from reactpy.core.events import event
11-
from reactpy.core.types import VdomDict
1211
from reactpy.web import export, module_from_file
1312

1413
from reactpy_django.forms.transforms import (
@@ -24,6 +23,8 @@
2423
if TYPE_CHECKING:
2524
from collections.abc import Sequence
2625

26+
from reactpy.core.types import VdomDict
27+
2728
DjangoForm = export(
2829
module_from_file("reactpy-django", file=Path(__file__).parent.parent / "static" / "reactpy_django" / "client.js"),
2930
("DjangoForm"),
@@ -44,6 +45,8 @@ def _django_form(
4445
top_children: Sequence,
4546
bottom_children: Sequence,
4647
):
48+
from reactpy_django import config
49+
4750
uuid_ref = hooks.use_ref(uuid4().hex.replace("-", ""))
4851
top_children_count = hooks.use_ref(len(top_children))
4952
bottom_children_count = hooks.use_ref(len(bottom_children))
@@ -84,7 +87,9 @@ async def render_form():
8487
await database_sync_to_async(initialized_form.save)()
8588
set_submitted_data(None)
8689

87-
new_form = await database_sync_to_async(initialized_form.render)(form_template)
90+
new_form = await database_sync_to_async(initialized_form.render)(
91+
form_template or config.REACTPY_DEFAULT_FORM_TEMPLATE
92+
)
8893
if new_form != rendered_form:
8994
set_rendered_form(new_form)
9095

0 commit comments

Comments
 (0)