mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[3.1.x] Fixed #31536 -- Fixed rendering of disabled AdminFileWidget and ClearableFileInput.
Backport of e46c2326c8 from master
			
			
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							22dac456f3
						
					
				
				
					commit
					56af541790
				
			| @@ -1,6 +1,6 @@ | |||||||
| {% if widget.is_initial %}<p class="file-upload">{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} | {% if widget.is_initial %}<p class="file-upload">{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} | ||||||
| <span class="clearable-file-input"> | <span class="clearable-file-input"> | ||||||
| <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"> | <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"{% if widget.attrs.disabled %} disabled{% endif %}> | ||||||
| <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label></span>{% endif %}<br> | <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label></span>{% endif %}<br> | ||||||
| {{ widget.input_text }}:{% endif %} | {{ widget.input_text }}:{% endif %} | ||||||
| <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>{% if widget.is_initial %}</p>{% endif %} | <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>{% if widget.is_initial %}</p>{% endif %} | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| {% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} | {% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} | ||||||
| <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"> | <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"{% if widget.attrs.disabled %} disabled{% endif %}> | ||||||
| <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br> | <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br> | ||||||
| {{ widget.input_text }}:{% endif %} | {{ widget.input_text }}:{% endif %} | ||||||
| <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}> | <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}> | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| {% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} | {% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %} | ||||||
| <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"> | <input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"{% if widget.attrs.disabled %} disabled{% endif %}> | ||||||
| <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br> | <label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br> | ||||||
| {{ widget.input_text }}:{% endif %} | {{ widget.input_text }}:{% endif %} | ||||||
| <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}> | <input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}> | ||||||
|   | |||||||
| @@ -487,6 +487,20 @@ class AdminFileWidgetTests(TestDataMixin, TestCase): | |||||||
|             }, |             }, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |     def test_render_disabled(self): | ||||||
|  |         widget = widgets.AdminFileWidget(attrs={'disabled': True}) | ||||||
|  |         self.assertHTMLEqual( | ||||||
|  |             widget.render('test', self.album.cover_art), | ||||||
|  |             '<p class="file-upload">Currently: <a href="%(STORAGE_URL)salbums/' | ||||||
|  |             r'hybrid_theory.jpg">albums\hybrid_theory.jpg</a> ' | ||||||
|  |             '<span class="clearable-file-input">' | ||||||
|  |             '<input type="checkbox" name="test-clear" id="test-clear_id" disabled>' | ||||||
|  |             '<label for="test-clear_id">Clear</label></span><br>' | ||||||
|  |             'Change: <input type="file" name="test" disabled></p>' % { | ||||||
|  |                 'STORAGE_URL': default_storage.url(''), | ||||||
|  |             }, | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def test_readonly_fields(self): |     def test_readonly_fields(self): | ||||||
|         """ |         """ | ||||||
|         File widgets should render as a link when they're marked "read only." |         File widgets should render as a link when they're marked "read only." | ||||||
|   | |||||||
| @@ -74,6 +74,21 @@ class ClearableFileInputTest(WidgetTest): | |||||||
|         """ |         """ | ||||||
|         self.check_html(self.widget, 'myfile', None, html='<input type="file" name="myfile">') |         self.check_html(self.widget, 'myfile', None, html='<input type="file" name="myfile">') | ||||||
|  |  | ||||||
|  |     def test_render_disabled(self): | ||||||
|  |         self.check_html( | ||||||
|  |             self.widget, | ||||||
|  |             'myfile', | ||||||
|  |             FakeFieldFile(), | ||||||
|  |             attrs={'disabled': True}, | ||||||
|  |             html=( | ||||||
|  |                 'Currently: <a href="something">something</a>' | ||||||
|  |                 '<input type="checkbox" name="myfile-clear" ' | ||||||
|  |                 'id="myfile-clear_id" disabled>' | ||||||
|  |                 '<label for="myfile-clear_id">Clear</label><br>' | ||||||
|  |                 'Change: <input type="file" name="myfile" disabled>' | ||||||
|  |             ), | ||||||
|  |         ) | ||||||
|  |  | ||||||
|     def test_render_as_subwidget(self): |     def test_render_as_subwidget(self): | ||||||
|         """A ClearableFileInput as a subwidget of MultiWidget.""" |         """A ClearableFileInput as a subwidget of MultiWidget.""" | ||||||
|         widget = MultiWidget(widgets=(self.widget,)) |         widget = MultiWidget(widgets=(self.widget,)) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user