mirror of https://github.com/django/django.git
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):
|
||||
copy = super().copy()
|
||||
copy.error_class = self.error_class
|
||||
copy.renderer = self.renderer
|
||||
return copy
|
||||
|
||||
def get_json_data(self, escape_html=False):
|
||||
|
|
|
@ -4849,6 +4849,12 @@ class RendererTests(SimpleTestCase):
|
|||
form = CustomForm(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):
|
||||
def test_iterate_radios(self):
|
||||
|
|
|
@ -2,6 +2,7 @@ import copy
|
|||
import json
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.forms.renderers import DjangoTemplates
|
||||
from django.forms.utils import (
|
||||
ErrorDict,
|
||||
ErrorList,
|
||||
|
@ -161,6 +162,17 @@ class FormsUtilsTestCase(SimpleTestCase):
|
|||
'<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):
|
||||
e = ErrorDict()
|
||||
e["__all__"] = ErrorList(
|
||||
|
|
Loading…
Reference in New Issue