aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/response.py
diff options
context:
space:
mode:
authorSebastian Spaeth <Sebastian@SSpaeth.de>2012-11-16 09:12:34 +0100
committerSebastian Spaeth <Sebastian@SSpaeth.de>2012-12-21 08:10:48 +0100
commit4487d51c819dcf34d335dd9efc57d03cf7c7ed1e (patch)
treeb6af7f9c11ebd9e3f9229ce2c4bf001b45fa6afa /mediagoblin/tools/response.py
parent30bb4109bc960153b66019360e0ed3e83a2dec88 (diff)
downloadmediagoblin-4487d51c819dcf34d335dd9efc57d03cf7c7ed1e.tar.lz
mediagoblin-4487d51c819dcf34d335dd9efc57d03cf7c7ed1e.tar.xz
mediagoblin-4487d51c819dcf34d335dd9efc57d03cf7c7ed1e.zip
Extend redirect helper to take optional location keyword
In order to move away from webob with its redirect(location=...) we need to provide a redirect function that allows to directly specify the URL rather than the urlgen parameters that we now use. Extend our MG.tools:redirect helper so we can pass in the direct URL via the optional "location" keyword. This commit does not switch over any redirect consumers yet. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/tools/response.py')
-rw-r--r--mediagoblin/tools/response.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/mediagoblin/tools/response.py b/mediagoblin/tools/response.py
index 81939a77..ed23f0f7 100644
--- a/mediagoblin/tools/response.py
+++ b/mediagoblin/tools/response.py
@@ -14,7 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from webob import Response, exc
+import werkzeug.utils
+from webob import Response
from mediagoblin.tools.template import render_template
from mediagoblin.tools.translate import (lazy_pass_to_ugettext as _,
pass_to_ugettext)
@@ -57,15 +58,21 @@ def render_404(request):
"you're looking for has been moved or deleted.")
return render_error(request, 404, err_msg=err_msg)
+
def redirect(request, *args, **kwargs):
- """Returns a HTTPFound(), takes a request and then urlgen params"""
+ """Redirects to an URL, using urlgen params or location string
+
+ :param querystring: querystring to be appended to the URL
+ :param location: If the location keyword is given, redirect to the URL
+ """
+ querystring = kwargs.pop('querystring', None)
- querystring = None
- if kwargs.get('querystring'):
- querystring = kwargs.get('querystring')
- del kwargs['querystring']
+ # Redirect to URL if given by "location=..."
+ if 'location' in kwargs:
+ location = kwargs.pop('location')
+ else:
+ location = request.urlgen(*args, **kwargs)
- return exc.HTTPFound(
- location=''.join([
- request.urlgen(*args, **kwargs),
- querystring if querystring else '']))
+ if querystring:
+ location += querystring
+ return werkzeug.utils.redirect(location)