mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #28585 -- Calculated admin's change form multipart context variable from forms and formsets
Thanks Tim Graham for the review.
This commit is contained in:
@@ -56,10 +56,11 @@ from .models import (
|
||||
UnorderedObject, Villain, Vodcast, Whatsit, Widget, Worker, WorkHour,
|
||||
)
|
||||
|
||||
|
||||
ERROR_MESSAGE = "Please enter the correct username and password \
|
||||
for a staff account. Note that both fields may be case-sensitive."
|
||||
|
||||
MULTIPART_ENCTYPE = 'enctype="multipart/form-data"'
|
||||
|
||||
|
||||
class AdminFieldExtractionMixin:
|
||||
"""
|
||||
@@ -3522,6 +3523,13 @@ class AdminInlineFileUploadTest(TestCase):
|
||||
self.picture = Picture(name="Test Picture", image=filename, gallery=self.gallery)
|
||||
self.picture.save()
|
||||
|
||||
def test_form_has_multipart_enctype(self):
|
||||
response = self.client.get(
|
||||
reverse('admin:admin_views_gallery_change', args=(self.gallery.id,))
|
||||
)
|
||||
self.assertIs(response.context['has_file_field'], True)
|
||||
self.assertContains(response, MULTIPART_ENCTYPE)
|
||||
|
||||
def test_inline_file_upload_edit_validation_error_post(self):
|
||||
"""
|
||||
Inline file uploads correctly display prior data (#10002).
|
||||
@@ -3658,6 +3666,10 @@ class AdminInlineTests(TestCase):
|
||||
response = self.client.get(collector_url)
|
||||
self.assertContains(response, 'name="widget_set-0-id"')
|
||||
|
||||
# No file or image fields, no enctype on the forms
|
||||
self.assertIs(response.context['has_file_field'], False)
|
||||
self.assertNotContains(response, MULTIPART_ENCTYPE)
|
||||
|
||||
# Now resave that inline
|
||||
self.post_data['widget_set-INITIAL_FORMS'] = "1"
|
||||
self.post_data['widget_set-0-id'] = str(widget_id)
|
||||
@@ -5451,7 +5463,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
|
||||
|
||||
# Check the form action.
|
||||
form_action = re.search(
|
||||
'<form enctype="multipart/form-data" action="(.*?)" method="post" id="user_form".*?>',
|
||||
'<form action="(.*?)" method="post" id="user_form".*?>',
|
||||
force_text(response.content)
|
||||
)
|
||||
self.assertURLEqual(form_action.group(1), '?%s' % self.get_preserved_filters_querystring())
|
||||
@@ -5515,7 +5527,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
|
||||
|
||||
# Check the form action.
|
||||
form_action = re.search(
|
||||
'<form enctype="multipart/form-data" action="(.*?)" method="post" id="user_form".*?>',
|
||||
'<form action="(.*?)" method="post" id="user_form".*?>',
|
||||
force_text(response.content)
|
||||
)
|
||||
self.assertURLEqual(form_action.group(1), '?%s' % self.get_preserved_filters_querystring())
|
||||
|
||||
Reference in New Issue
Block a user