Fixed #19773 - Added admin/popup_response.html template.

Thanks jimmylam@ for the suggestion.
This commit is contained in:
Javier Mansilla 2013-02-26 00:27:52 -03:00 committed by Tim Graham
parent e10757ff4d
commit f819bef3dc
4 changed files with 27 additions and 8 deletions

View File

@ -24,7 +24,7 @@ from django.db.models.constants import LOOKUP_SEP
from django.db.models.related import RelatedObject from django.db.models.related import RelatedObject
from django.db.models.fields import BLANK_CHOICE_DASH, FieldDoesNotExist from django.db.models.fields import BLANK_CHOICE_DASH, FieldDoesNotExist
from django.db.models.sql.constants import QUERY_TERMS 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.http.response import HttpResponseBase
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.template.response import SimpleTemplateResponse, TemplateResponse from django.template.response import SimpleTemplateResponse, TemplateResponse
@ -911,11 +911,10 @@ class ModelAdmin(BaseModelAdmin):
# Here, we distinguish between different save types by checking for # Here, we distinguish between different save types by checking for
# the presence of keys in request.POST. # the presence of keys in request.POST.
if IS_POPUP_VAR in request.POST: if IS_POPUP_VAR in request.POST:
return HttpResponse( return SimpleTemplateResponse('admin/popup_response.html', {
'<!DOCTYPE html><html><head><title></title></head><body>' 'pk_value': escape(pk_value),
'<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script></body></html>' % \ 'obj': escapejs(obj)
# escape() calls force_text. })
(escape(pk_value), escapejs(obj)))
elif "_continue" in request.POST: elif "_continue" in request.POST:
msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict

View File

@ -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>

View File

@ -137,7 +137,7 @@ class Thing(models.Model):
class Actor(models.Model): class Actor(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
age = models.IntegerField() age = models.IntegerField()
title = models.CharField(max_length=50, null=True) title = models.CharField(max_length=50, null=True, blank=True)
def __str__(self): def __str__(self):
return self.name return self.name

View File

@ -2554,6 +2554,17 @@ action)</option>
'/test_admin/admin/admin_views/subscriber/?%s' % IS_POPUP_VAR) '/test_admin/admin/admin_views/subscriber/?%s' % IS_POPUP_VAR)
self.assertEqual(response.context["action_form"], None) 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',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class TestCustomChangeList(TestCase): class TestCustomChangeList(TestCase):
@ -4275,7 +4286,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
# Get the `add_view`. # Get the `add_view`.
response = self.client.get(self.get_add_url()) response = self.client.get(self.get_add_url())
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
# Check the form action. # Check the form action.
form_action = """<form enctype="multipart/form-data" action="?%s" method="post" id="user_form">""" % self.get_preserved_filters_querystring() form_action = """<form enctype="multipart/form-data" action="?%s" method="post" id="user_form">""" % self.get_preserved_filters_querystring()
self.assertContains(response, form_action, count=1) self.assertContains(response, form_action, count=1)