Ticket #16842: django-redirects-querystring.patch

File django-redirects-querystring.patch, 2.4 KB (added by jamey@…, 12 years ago)
  • tests/regressiontests/generic_views/base.py

     
    256256        self.assertEqual(response.status_code, 301)
    257257        self.assertEqual(response['Location'], '/bar/?pork=spam')
    258258
     259    def test_include_urlencoded_args(self):
     260        "GET arguments can be URL-encoded when included in the redirected URL"
     261        response = RedirectView.as_view(url='/bar/', query_string=True)(self.rf.get('/foo/?unicode=%E2%9C%93'))
     262        self.assertEqual(response.status_code, 301)
     263        self.assertEqual(response['Location'], '/bar/?unicode=%E2%9C%93')
     264
    259265    def test_parameter_substitution(self):
    260266        "Redirection URLs can be parameterized"
    261267        response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)
  • django/views/generic/simple.py

     
    4848    from the request is appended to the URL.
    4949
    5050    """
    51     args = request.META["QUERY_STRING"]
    52     if args and query_string and url is not None:
    53         url = "%s?%s" % (url, args)
     51    if url is not None:
     52        url = url % kwargs
     53        args = request.META["QUERY_STRING"]
     54        if args and query_string:
     55            url = "%s?%s" % (url, args)
    5456
    55     if url is not None:
    5657        klass = permanent and HttpResponsePermanentRedirect or HttpResponseRedirect
    57         return klass(url % kwargs)
     58        return klass(url)
    5859    else:
    5960        logger.warning('Gone: %s' % request.path,
    6061                    extra={
  • django/views/generic/base.py

     
    138138        are provided as kwargs to this method.
    139139        """
    140140        if self.url:
     141            url = self.url % kwargs
    141142            args = self.request.META["QUERY_STRING"]
    142143            if args and self.query_string:
    143                 url = "%s?%s" % (self.url, args)
    144             else:
    145                 url = self.url
    146             return url % kwargs
     144                url = "%s?%s" % (url, args)
     145            return url
    147146        else:
    148147            return None
    149148
Back to Top