Fixed #33134 -- Fixed recursion depth error when rendering Form with BoundFields.
Regression in 456466d932
.
This commit is contained in:
parent
b7fd668b37
commit
4884a87e02
|
@ -177,7 +177,6 @@ class BoundField:
|
||||||
else:
|
else:
|
||||||
attrs['class'] = self.form.required_css_class
|
attrs['class'] = self.form.required_css_class
|
||||||
context = {
|
context = {
|
||||||
'form': self.form,
|
|
||||||
'field': self,
|
'field': self,
|
||||||
'label': contents,
|
'label': contents,
|
||||||
'attrs': attrs,
|
'attrs': attrs,
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
{% load tags %}
|
||||||
|
{% count_render %}
|
|
@ -0,0 +1,21 @@
|
||||||
|
from django.template import Library, Node
|
||||||
|
|
||||||
|
register = Library()
|
||||||
|
|
||||||
|
|
||||||
|
class CountRenderNode(Node):
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
def render(self, context):
|
||||||
|
self.count += 1
|
||||||
|
for v in context.flatten().values():
|
||||||
|
try:
|
||||||
|
v.render()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
return str(self.count)
|
||||||
|
|
||||||
|
|
||||||
|
@register.tag
|
||||||
|
def count_render(parser, token):
|
||||||
|
return CountRenderNode()
|
|
@ -3954,3 +3954,14 @@ class OverrideTests(SimpleTestCase):
|
||||||
'<div class="error">This field is required.</div></div>'
|
'<div class="error">This field is required.</div></div>'
|
||||||
'<p>Comment: <input type="text" name="comment" required></p>',
|
'<p>Comment: <input type="text" name="comment" required></p>',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_cyclic_context_boundfield_render(self):
|
||||||
|
class FirstNameForm(Form):
|
||||||
|
first_name = CharField()
|
||||||
|
template_name_label = 'forms_tests/cyclic_context_boundfield_render.html'
|
||||||
|
|
||||||
|
f = FirstNameForm()
|
||||||
|
try:
|
||||||
|
self.assertInHTML('<th>1</th>', f.render())
|
||||||
|
except RecursionError:
|
||||||
|
self.fail('Cyclic reference in BoundField.render().')
|
||||||
|
|
Loading…
Reference in New Issue