mirror of https://github.com/django/django.git
Fixed #19773 - Added admin/popup_response.html template.
Thanks jimmylam@ for the suggestion.
This commit is contained in:
parent
e10757ff4d
commit
f819bef3dc
|
@ -24,7 +24,7 @@ from django.db.models.constants import LOOKUP_SEP
|
|||
from django.db.models.related import RelatedObject
|
||||
from django.db.models.fields import BLANK_CHOICE_DASH, FieldDoesNotExist
|
||||
from django.db.models.sql.constants import QUERY_TERMS
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.http.response import HttpResponseBase
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.template.response import SimpleTemplateResponse, TemplateResponse
|
||||
|
@ -911,11 +911,10 @@ class ModelAdmin(BaseModelAdmin):
|
|||
# Here, we distinguish between different save types by checking for
|
||||
# the presence of keys in request.POST.
|
||||
if IS_POPUP_VAR in request.POST:
|
||||
return HttpResponse(
|
||||
'<!DOCTYPE html><html><head><title></title></head><body>'
|
||||
'<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script></body></html>' % \
|
||||
# escape() calls force_text.
|
||||
(escape(pk_value), escapejs(obj)))
|
||||
return SimpleTemplateResponse('admin/popup_response.html', {
|
||||
'pk_value': escape(pk_value),
|
||||
'obj': escapejs(obj)
|
||||
})
|
||||
|
||||
elif "_continue" in request.POST:
|
||||
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title></title></head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
opener.dismissAddAnotherPopup(window, "{{ pk_value }}", "{{ obj }}");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -137,7 +137,7 @@ class Thing(models.Model):
|
|||
class Actor(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
age = models.IntegerField()
|
||||
title = models.CharField(max_length=50, null=True)
|
||||
title = models.CharField(max_length=50, null=True, blank=True)
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
|
|
@ -2554,6 +2554,17 @@ action)</option>
|
|||
'/test_admin/admin/admin_views/subscriber/?%s' % IS_POPUP_VAR)
|
||||
self.assertEqual(response.context["action_form"], None)
|
||||
|
||||
def test_popup_template_response(self):
|
||||
"""
|
||||
Success on popups shall be rendered from template in order to allow
|
||||
easy customization.
|
||||
"""
|
||||
response = self.client.post(
|
||||
'/test_admin/admin/admin_views/actor/add/?%s=1' % IS_POPUP_VAR,
|
||||
{'name': 'Troy McClure', 'age': '55', IS_POPUP_VAR: '1'})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.template_name, 'admin/popup_response.html')
|
||||
|
||||
|
||||
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
|
||||
class TestCustomChangeList(TestCase):
|
||||
|
|
Loading…
Reference in New Issue