Commit f819bef3 authored by Javier Mansilla's avatar Javier Mansilla Committed by Tim Graham
Browse files

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

Thanks jimmylam@ for the suggestion.
parent e10757ff
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -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
+9 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html>
  <head><title></title></head>
  <body>
    <script type="text/javascript">
      opener.dismissAddAnotherPopup(window, "{{ pk_value }}", "{{ obj }}");
    </script>
  </body>
</html>
+1 −1
Original line number Diff line number Diff line
@@ -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

+12 −1
Original line number Diff line number Diff line
@@ -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):