Skip to content

Commit

Permalink
port the bugfix for accepting and passing on the status and redirect …
Browse files Browse the repository at this point in the history
…arguments to the redirect method
  • Loading branch information
janwijbrand committed Jun 1, 2010
1 parent 66b1948 commit 6e5a917
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
6 changes: 3 additions & 3 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Changes
=======

1.14.0 (unreleased)
1.13.4 (unreleased)
-------------------

- None yet.

- Fix the url() method to accept the "status" and "trusted" arguments, passed
on to the redirect method on the response object.

1.13.3 (2010-05-27)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def read(*rnames):

setup(
name='grokcore.view',
version = '1.14.0dev',
version = '1.13.4dev',
author='Grok Team',
author_email='grok-dev@zope.org',
url='http://grok.zope.org',
Expand Down
5 changes: 3 additions & 2 deletions src/grokcore/view/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def response(self):
def body(self):
return self.request.bodyStream.getCacheStream().read()

def redirect(self, url):
return self.request.response.redirect(url)
def redirect(self, url, status=None, trusted=False):
return self.request.response.redirect(
url, status=status, trusted=trusted)

def url(self, obj=None, name=None, data=None):
"""Return string for the URL based on the obj and name.
Expand Down
22 changes: 20 additions & 2 deletions src/grokcore/view/ftests/url/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
>>> browser.open('http://localhost/manfred')
>>> browser.url
'http://localhost/manfred/another'
>>> browser.open('http://localhost/manfred/trustedredirect')
>>> browser.url
'http://www.google.com/'
>>> browser.open('http://localhost/manfred/redirectwithstatus')
Traceback (most recent call last):
...
HTTPError: HTTP Error 418: Unknown
>>> browser.url
'http://localhost/manfred/redirectwithstatus'
"""
import grokcore.view as grok

Expand All @@ -23,7 +34,14 @@ class Index(grok.View):
def render(self):
self.redirect(self.url('another'))

class TrustedRedirect(grok.View):
def render(self):
self.redirect('http://www.google.com/ncr', trusted=True)

class RedirectWithStatus(grok.View):
def render(self):
self.redirect(self.url(), status=418)

class Another(grok.View):
def render(self):
return "Another view"

0 comments on commit 6e5a917

Please sign in to comment.