Exemplo n.º 1
0
    def response_cancel(self, request, obj):
        """Determine the HttpResponse for the cancel_order_view stage."""
        opts = self.model._meta

        msg_dict = {
            'name':
            force_text(opts.verbose_name),
            'obj':
            format_html('<a href="{0}">{1}</a>', urlquote(request.path), obj),
        }
        msg = format_html(
            _('The {name} "{obj}" was cancelled successfully.'),
            **msg_dict,
        )
        self.message_user(request, msg, messages.SUCCESS)

        preserved_filters = self.get_preserved_filters(request)
        redirect_url = add_preserved_filters(
            {
                'preserved_filters': preserved_filters,
                'opts': opts
            },
            get_change_url(obj),
        )
        return HttpResponseRedirect(redirect_url)
Exemplo n.º 2
0
 def test_returns_empty_string_if_obj_is_none(self):
     """Test that if None is passed, an empty URL is returned."""
     assert get_change_url(None) == ''
Exemplo n.º 3
0
 def test_returns_empty_string_if_no_pk(self):
     """Test that if the object has no pk, an empty URL is returned."""
     book = BookFactory.build()
     assert get_change_url(book) == ''
Exemplo n.º 4
0
 def test_generates_urls_for_saved_objects(self):
     """Test that a valid change URL is generated."""
     book = BookFactory()
     assert get_change_url(book) == (
         f'/admin/support/book/{book.pk}/change/')