mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	Fixed #25085 -- Overrode Select widget's __deepcopy__()
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							035b0fa60d
						
					
				
				
					commit
					8ee6a3f1a8
				
			| @@ -521,6 +521,13 @@ class Select(Widget): | |||||||
|         # more than once. |         # more than once. | ||||||
|         self.choices = list(choices) |         self.choices = list(choices) | ||||||
|  |  | ||||||
|  |     def __deepcopy__(self, memo): | ||||||
|  |         obj = copy.copy(self) | ||||||
|  |         obj.attrs = self.attrs.copy() | ||||||
|  |         obj.choices = copy.copy(self.choices) | ||||||
|  |         memo[id(self)] = obj | ||||||
|  |         return obj | ||||||
|  |  | ||||||
|     def render(self, name, value, attrs=None, choices=()): |     def render(self, name, value, attrs=None, choices=()): | ||||||
|         if value is None: |         if value is None: | ||||||
|             value = '' |             value = '' | ||||||
|   | |||||||
| @@ -1997,3 +1997,18 @@ class SelectDateWidgetTests(SimpleTestCase): | |||||||
|         # label tag is correctly associated with first rendered dropdown |         # label tag is correctly associated with first rendered dropdown | ||||||
|         a = GetDate({'mydate_month': '1', 'mydate_day': '1', 'mydate_year': '2010'}) |         a = GetDate({'mydate_month': '1', 'mydate_day': '1', 'mydate_year': '2010'}) | ||||||
|         self.assertIn('<label for="id_mydate_day">', a.as_p()) |         self.assertIn('<label for="id_mydate_day">', a.as_p()) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class SelectWidgetTests(SimpleTestCase): | ||||||
|  |  | ||||||
|  |     def test_deepcopy(self): | ||||||
|  |         """ | ||||||
|  |         __deepcopy__() should copy all attributes properly (#25085). | ||||||
|  |         """ | ||||||
|  |         widget = Select() | ||||||
|  |         obj = copy.deepcopy(widget) | ||||||
|  |         self.assertTrue(widget is not obj) | ||||||
|  |         self.assertEqual(widget.choices, obj.choices) | ||||||
|  |         self.assertTrue(widget.choices is not obj.choices) | ||||||
|  |         self.assertEqual(widget.attrs, obj.attrs) | ||||||
|  |         self.assertTrue(widget.attrs is not obj.attrs) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user