Create redirect shortcut and use it around
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 5 Jun 2011 13:49:08 +0000 (15:49 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 5 Jun 2011 14:16:03 +0000 (16:16 +0200)
This is just replacing exc.HTTPFound(location=request.urlgen(...))
by redirect(request, ...). No magic.

mediagoblin/auth/views.py
mediagoblin/decorators.py
mediagoblin/edit/views.py
mediagoblin/submit/views.py
mediagoblin/util.py

index d54e673cfc618c785060fbb44d3a8134cbfc4645..36d23e53c12f75f393ab59cd4b35cce637227a90 100644 (file)
@@ -18,7 +18,7 @@ import uuid
 
 from webob import exc
 
-from mediagoblin.util import render_to_response
+from mediagoblin.util import render_to_response, redirect
 from mediagoblin.db.util import ObjectId
 from mediagoblin.auth import lib as auth_lib
 from mediagoblin.auth import forms as auth_forms
@@ -54,9 +54,7 @@ def register(request):
             
             send_verification_email(entry, request)
 
-            # Redirect to register_success
-            return exc.HTTPFound(
-                location=request.urlgen("mediagoblin.auth.register_success"))
+            return redirect(request, "mediagoblin.auth.register_success")
 
     return render_to_response(request,
         'mediagoblin/auth/register.html',
@@ -90,8 +88,7 @@ def login(request):
             if request.POST.get('next'):
                 return exc.HTTPFound(location=request.POST['next'])
             else:
-                return exc.HTTPFound(
-                    location=request.urlgen("index"))
+                return redirect(request, "index")
 
         else:
             # Prevent detecting who's on this system by testing login
@@ -110,8 +107,7 @@ def logout(request):
     # Maybe deleting the user_id parameter would be enough?
     request.session.delete()
     
-    return exc.HTTPFound(
-        location=request.urlgen("index"))
+    return redirect(request, "index")
 
 
 def verify_email(request):
@@ -164,8 +160,7 @@ def resend_activation(request):
 
     send_verification_email(request.user, request)
 
-    return exc.HTTPFound(
-        location=request.urlgen('mediagoblin.auth.resend_verification_success'))
+    return redirect(request, 'mediagoblin.auth.resend_verification_success')
 
 
 def resend_activation_success(request):
index 345753208cc51dc9402c91acb7acc6f85cb1b4b1..c2fe3f9fdbf0bd7db962e197589b0f1c6e8aadfc 100644 (file)
@@ -18,6 +18,7 @@
 from bson.errors import InvalidId
 from webob import exc
 
+from mediagoblin.util import redirect
 from mediagoblin.db.util import ObjectId
 
 
@@ -38,9 +39,8 @@ def require_active_login(controller):
     def new_controller_func(request, *args, **kwargs):
         if request.user and \
                 request.user.get('status') == u'needs_email_verification':
-            return exc.HTTPFound(
-                location = request.urlgen(
-                    'mediagoblin.auth.verify_email_notice'))
+            return redirect(request,
+                    'mediagoblin.auth.verify_email_notice')
         elif not request.user or request.user.get('status') != u'active':
             return exc.HTTPFound(
                 location="%s?next=%s" % (
index 258f14e383006b9bfc939f5587a018ae44229e8b..04b735677f339b8601716475af6ed5722a3e206a 100644 (file)
@@ -17,7 +17,7 @@
 
 from webob import exc
 
-from mediagoblin.util import render_to_response
+from mediagoblin.util import render_to_response, redirect
 from mediagoblin.edit import forms
 from mediagoblin.edit.lib import may_edit_media
 from mediagoblin.decorators import require_active_login, get_user_media_entry
@@ -51,10 +51,8 @@ def edit_media(request, media):
             media['slug'] = request.POST['slug']
             media.save()
 
-            # redirect
-            return exc.HTTPFound(
-                location=request.urlgen("mediagoblin.user_pages.media_home",
-                    user=media.uploader()['username'], media=media['slug']))
+            return redirect(request, "mediagoblin.user_pages.media_home",
+                user=media.uploader()['username'], media=media['slug'])
 
     return render_to_response(request,
         'mediagoblin/edit/edit.html',
index 95257b72205d89d8980bdb20735b21baa45b987c..d4ecc75a84498dd77a168a1421d544c83994681f 100644 (file)
 from os.path import splitext
 from cgi import FieldStorage
 
-from webob import exc
 from werkzeug.utils import secure_filename
 
-from mediagoblin.util import render_to_response
+from mediagoblin.util import render_to_response, redirect
 from mediagoblin.decorators import require_active_login
 from mediagoblin.submit import forms as submit_forms
 from mediagoblin.process_media import process_media_initial
@@ -76,9 +75,7 @@ def submit_start(request):
             # queue it for processing
             process_media_initial.delay(unicode(entry['_id']))
 
-            # redirect
-            return exc.HTTPFound(
-                location=request.urlgen("mediagoblin.submit.success"))
+            return redirect(request, "mediagoblin.submit.success")
 
     return render_to_response(request,
         'mediagoblin/submit/start.html',
index f69c91f26a576ef24633e179655c0ddc7df01b35..a0a09adf5c601a7cce307c5deaae8da9e4aa5e94 100644 (file)
@@ -29,7 +29,7 @@ from babel.localedata import exists
 import jinja2
 import translitcodec
 from paste.deploy.loadwsgi import NicerConfigParser
-from webob import Response
+from webob import Response, exc
 
 from mediagoblin import globals as mgoblin_globals
 from mediagoblin.db.util import ObjectId
@@ -123,6 +123,11 @@ def render_to_response(request, template, context):
     return Response(render_template(request, template, context))
 
 
+def redirect(request, *args, **kwargs):
+    """Returns a HTTPFound(), takes a request and then urlgen params"""
+    return exc.HTTPFound(location=request.urlgen(*args, **kwargs))
+
+
 def setup_user_in_request(request):
     """
     Examine a request and tack on a request.user parameter if that's