Fixed #19298 -- Added MultiValueField.__deepcopy__
Thanks nick.phillips at otago.ac.nz for the report.
This commit is contained in:
parent
d5d0e03ec8
commit
4e96dac450
|
@ -977,6 +977,11 @@ class MultiValueField(Field):
|
||||||
f.required = False
|
f.required = False
|
||||||
self.fields = fields
|
self.fields = fields
|
||||||
|
|
||||||
|
def __deepcopy__(self, memo):
|
||||||
|
result = super(MultiValueField, self).__deepcopy__(memo)
|
||||||
|
result.fields = tuple([x.__deepcopy__(memo) for x in self.fields])
|
||||||
|
return result
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
|
@ -1793,6 +1794,26 @@ class FormsTestCase(TestCase):
|
||||||
self.assertTrue(form.is_valid())
|
self.assertTrue(form.is_valid())
|
||||||
self.assertEqual(form.cleaned_data, {'name' : 'fname lname'})
|
self.assertEqual(form.cleaned_data, {'name' : 'fname lname'})
|
||||||
|
|
||||||
|
def test_multivalue_deep_copy(self):
|
||||||
|
"""
|
||||||
|
#19298 -- MultiValueField needs to override the default as it needs
|
||||||
|
to deep-copy subfields:
|
||||||
|
"""
|
||||||
|
class ChoicesField(MultiValueField):
|
||||||
|
def __init__(self, fields=(), *args, **kwargs):
|
||||||
|
fields = (ChoiceField(label='Rank',
|
||||||
|
choices=((1,1),(2,2))),
|
||||||
|
CharField(label='Name', max_length=10))
|
||||||
|
super(ChoicesField, self).__init__(fields=fields, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
field = ChoicesField()
|
||||||
|
field2 = copy.deepcopy(field)
|
||||||
|
self.assertTrue(isinstance(field2, ChoicesField))
|
||||||
|
self.assertFalse(id(field2.fields) == id(field.fields))
|
||||||
|
self.assertFalse(id(field2.fields[0].choices) ==
|
||||||
|
id(field.fields[0].choices))
|
||||||
|
|
||||||
def test_multivalue_optional_subfields(self):
|
def test_multivalue_optional_subfields(self):
|
||||||
class PhoneField(MultiValueField):
|
class PhoneField(MultiValueField):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue