#34532: Form.default_renderer is ignored in formsets.
----------------------------------+------------------------------------
Reporter: Ryan Burt | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 4.2
Severity: Normal | Resolution:
Keywords: default_renderer | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Christopher Cave-Ayland):
I've been looking at this as part of the sprints for DjangoCon EU. I've
put together
[https://github.com/cc-a/django/blob/ticket_34532/tests/forms_tests/tests/test_formsets.py#L1556-L1576
a test] (gist pasted below) that I believe captures the desired behaviour
discussed above.
{{{
def test_form_default_renderer(self):
"""
In the absense of a renderer passed to formset_factory, the
default_renderer
attribute of the Form class should be respected.
"""
from django.forms.renderers import Jinja2
class ChoiceWithDefaultRenderer(Choice):
default_renderer = Jinja2
data = {
"choices-TOTAL_FORMS": "1",
"choices-INITIAL_FORMS": "0",
"choices-MIN_NUM_FORMS": "0",
}
ChoiceFormSet = formset_factory(ChoiceWithDefaultRenderer,
renderer=None)
formset = ChoiceFormSet(data, auto_id=False, prefix="choices")
self.assertIsInstance(
formset.forms[0].renderer,
ChoiceWithDefaultRenderer.default_renderer
)
}}}
This test currently fails but can be made to pass via the above change
suggested via @RyanBurt.
The change unfortunately is breaking however and causes 14 other test
failures. The root cause seems to be that the `renderer` attribute for the
resulting formset class ends up as `None` even though it is expected not
to be.
To progress this ticket I think some more sophisticated changes to
BaseFormSet are required to determine the appropriate renderer to use for
forms. I'll aim to update after some further experimentation.,
--
Ticket URL: <https://code.djangoproject.com/ticket/34532#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018876fd160a-585dc5a6-9cec-4605-b8c4-71a81a96cbb6-000000%40eu-central-1.amazonses.com.