Skip to content

#18558 Supply `url` property to `HttpResponseRedirect` and `HttpResponsePermanentRedirect` #657

Closed
wants to merge 9 commits into from

2 participants

@hirokiky

I added line to HttpResponseBase and correspond tests.

@claudep claudep commented on an outdated diff Jan 18, 2013
tests/regressiontests/urlpatterns_reverse/tests.py
def test_redirect_view_object(self):
from .views import absolute_kwargs_view
res = redirect(absolute_kwargs_view)
self.assertEqual(res['Location'], '/absolute_arg_view/')
+ self.assertEqual(res.url, '/absolute_arg_view/')
self.assertRaises(NoReverseMatch, redirect, absolute_kwargs_view, wrong_argument=None)
@claudep
Django member
claudep added a note Jan 18, 2013

I think that testing once that res['Location'] == res.url would be sufficient. Then later only test res.url. This should be documented, in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hirokiky

Now, testing of url property appears one time. and all tests use this property.

@claudep claudep and 1 other commented on an outdated diff Jan 19, 2013
tests/regressiontests/httpwrappers/tests.py
@@ -410,6 +410,8 @@ def test_redirect(self):
content='The resource has temporarily moved',
content_type='text/html')
self.assertContains(response, 'The resource has temporarily moved', status_code=302)
+ # Test that url attribute is right
+ self.assertEqual(response.url, response.url)
@claudep
Django member
claudep added a note Jan 19, 2013

Erm... really? :-)

@hirokiky
hirokiky added a note Jan 19, 2013

Thank you very much. It's my careless mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@claudep claudep commented on an outdated diff Jan 19, 2013
docs/ref/request-response.txt
.. class:: HttpResponsePermanentRedirect
Like :class:`HttpResponseRedirect`, but it returns a permanent redirect
(HTTP status code 301) instead of a "found" redirect (status code 302).
+ .. attribute:: HttpResponsePermanentRedirect.url
+
+ This attribute represents a path to redirect.
+
.. class:: HttpResponseNotModified
The constructor doesn't take any arguments and no content should be added
@claudep
Django member
claudep added a note Jan 19, 2013

A versionadded directive is missing in both snippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hirokiky

I added description about this new feature to document as new feature for Django 1.6.
I have read document about writing documentation (https://docs.djangoproject.com/en/dev/internals/contributing/writing-documentation/#documenting-new-features) .
Is this changesets correct?

@claudep
Django member
claudep commented Feb 13, 2013

Thanks, committed in e94f405

@claudep claudep closed this Feb 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.