mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
Fixed #35987 -- Made ErrorList.copy() copy the renderer attribute.
This commit is contained in:
parent
02628c051c
commit
4806c42efa
@ -163,6 +163,7 @@ class ErrorList(UserList, list, RenderableErrorMixin):
|
|||||||
def copy(self):
|
def copy(self):
|
||||||
copy = super().copy()
|
copy = super().copy()
|
||||||
copy.error_class = self.error_class
|
copy.error_class = self.error_class
|
||||||
|
copy.renderer = self.renderer
|
||||||
return copy
|
return copy
|
||||||
|
|
||||||
def get_json_data(self, escape_html=False):
|
def get_json_data(self, escape_html=False):
|
||||||
|
@ -4849,6 +4849,12 @@ class RendererTests(SimpleTestCase):
|
|||||||
form = CustomForm(renderer=custom)
|
form = CustomForm(renderer=custom)
|
||||||
self.assertEqual(form.renderer, custom)
|
self.assertEqual(form.renderer, custom)
|
||||||
|
|
||||||
|
def test_get_context_errors(self):
|
||||||
|
custom = CustomRenderer()
|
||||||
|
form = Form(renderer=custom)
|
||||||
|
context = form.get_context()
|
||||||
|
self.assertEqual(context["errors"].renderer, custom)
|
||||||
|
|
||||||
|
|
||||||
class TemplateTests(SimpleTestCase):
|
class TemplateTests(SimpleTestCase):
|
||||||
def test_iterate_radios(self):
|
def test_iterate_radios(self):
|
||||||
|
@ -2,6 +2,7 @@ import copy
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.forms.renderers import DjangoTemplates
|
||||||
from django.forms.utils import (
|
from django.forms.utils import (
|
||||||
ErrorDict,
|
ErrorDict,
|
||||||
ErrorList,
|
ErrorList,
|
||||||
@ -161,6 +162,17 @@ class FormsUtilsTestCase(SimpleTestCase):
|
|||||||
'<a href="http://www.example.com/">example</a></li></ul>',
|
'<a href="http://www.example.com/">example</a></li></ul>',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_error_list_copy_attributes(self):
|
||||||
|
class CustomRenderer(DjangoTemplates):
|
||||||
|
pass
|
||||||
|
|
||||||
|
renderer = CustomRenderer()
|
||||||
|
e = ErrorList(error_class="woopsies", renderer=renderer)
|
||||||
|
|
||||||
|
e_copy = e.copy()
|
||||||
|
self.assertEqual(e.error_class, e_copy.error_class)
|
||||||
|
self.assertEqual(e.renderer, e_copy.renderer)
|
||||||
|
|
||||||
def test_error_dict_copy(self):
|
def test_error_dict_copy(self):
|
||||||
e = ErrorDict()
|
e = ErrorDict()
|
||||||
e["__all__"] = ErrorList(
|
e["__all__"] = ErrorList(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user