Create render_to_reponse and use it everywhere.
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 5 Jun 2011 13:25:45 +0000 (15:25 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Sun, 5 Jun 2011 14:16:03 +0000 (16:16 +0200)
Just a shortcut for Response(render_template(...))

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

index 2d24328d65830ad9f2a247b4980361854ac77eec..a5112299f2fd831fd9a1ec1b0285a4c9c3945413 100644 (file)
@@ -16,9 +16,9 @@
 
 import uuid
 
-from webob import Response, exc
+from webob import exc
 
-from mediagoblin.util import render_template
+from mediagoblin.util import render_to_response
 from mediagoblin.db.util import ObjectId
 from mediagoblin.auth import lib as auth_lib
 from mediagoblin.auth import forms as auth_forms
@@ -59,16 +59,14 @@ def register(request):
                 location=request.urlgen("mediagoblin.auth.register_success"))
 
     # render
-    return Response(
-        render_template(
+    return render_to_response(
             request, 'mediagoblin/auth/register.html',
-            {'register_form': register_form}))
+            {'register_form': register_form})
 
 
 def register_success(request):
-    return Response(
-        render_template(
-            request, 'mediagoblin/auth/register_success.html', {}))
+    return render_to_response(
+            request, 'mediagoblin/auth/register_success.html', {})
 
 
 def login(request):
@@ -103,12 +101,11 @@ def login(request):
             login_failed = True
 
     # render
-    return Response(
-        render_template(
+    return render_to_response(
             request, 'mediagoblin/auth/login.html',
             {'login_form': login_form,
              'next': request.GET.get('next') or request.POST.get('next'),
-             'login_failed': login_failed}))
+             'login_failed': login_failed})
 
 
 def logout(request):
@@ -141,11 +138,10 @@ def verify_email(request):
     else:
         verification_successful = False
         
-    return Response(
-        render_template(
+    return render_to_response(
             request, 'mediagoblin/auth/verify_email.html',
             {'user': user,
-             'verification_successful': verification_successful}))
+             'verification_successful': verification_successful})
 
 def verify_email_notice(request):
     """
@@ -154,9 +150,8 @@ def verify_email_notice(request):
     When the user tries to do some action that requires their account
     to be verified beforehand, this view is called upon!
     """
-    return Response(
-        render_template(
-            request, 'mediagoblin/auth/verification_needed.html', {}))
+    return render_to_response(
+            request, 'mediagoblin/auth/verification_needed.html', {})
 
 
 def resend_activation(request):
@@ -176,6 +171,5 @@ def resend_activation(request):
 
 
 def resend_activation_success(request):
-    return Response(
-        render_template(
-            request, 'mediagoblin/auth/resent_verification_email.html', {}))
+    return render_to_response(
+            request, 'mediagoblin/auth/resent_verification_email.html', {})
index 027a426c40028978b128680e3c0b1656918e99eb..ac286bec793567b42523f5aabb39ffa1aab60d8c 100644 (file)
@@ -15,9 +15,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-from webob import Response, exc
+from webob import exc
 
-from mediagoblin.util import render_template
+from mediagoblin.util import render_to_response
 from mediagoblin.edit import forms
 from mediagoblin.edit.lib import may_edit_media
 from mediagoblin.decorators import require_active_login, get_user_media_entry
@@ -57,8 +57,7 @@ def edit_media(request, media):
                     user=media.uploader()['username'], media=media['slug']))
 
     # render
-    return Response(
-        render_template(
+    return render_to_response(
             request, 'mediagoblin/edit/edit.html',
             {'media': media,
-             'form': form}))
+             'form': form})
index 256f5be9190781f3ac40a6f6f8f5b274ecb3d04b..a51e14e60a6f8eb3ea2a8d4c21645e540f240c43 100644 (file)
 from os.path import splitext
 from cgi import FieldStorage
 
-from webob import Response, exc
+from webob import exc
 from werkzeug.utils import secure_filename
 
-from mediagoblin.util import render_template
+from mediagoblin.util import render_to_response
 from mediagoblin.decorators import require_active_login
 from mediagoblin.submit import forms as submit_forms
 from mediagoblin.process_media import process_media_initial
@@ -81,14 +81,12 @@ def submit_start(request):
                 location=request.urlgen("mediagoblin.submit.success"))
 
     # render
-    return Response(
-        render_template(
+    return render_to_response(
             request, 'mediagoblin/submit/start.html',
-            {'submit_form': submit_form}))
+            {'submit_form': submit_form})
 
 
 def submit_success(request):
     # render
-    return Response(
-        render_template(
-            request, 'mediagoblin/submit/success.html', {}))
+    return render_to_response(
+            request, 'mediagoblin/submit/success.html', {})
index 6ea3fe36b04ee47bfb9320b95237832622424908..0442e736199e26a98360b678c47c33a1763553f6 100644 (file)
@@ -14,9 +14,9 @@
 # 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
+from webob import exc
 from mediagoblin.db.util import DESCENDING
-from mediagoblin.util import Pagination, render_template
+from mediagoblin.util import Pagination, render_to_response
 
 from mediagoblin.decorators import uses_pagination, get_user_media_entry
 
@@ -42,21 +42,19 @@ def user_home(request, page):
     if media_entries == None:
         return exc.HTTPNotFound()
     
-    return Response(
-        render_template(
+    return render_to_response(
             request, 'mediagoblin/user_pages/user.html',
             {'user': user,
              'media_entries': media_entries,
-             'pagination': pagination}))
+             'pagination': pagination})
 
 
 @get_user_media_entry
 def media_home(request, media):
     """'Homepage' of a MediaEntry()"""
-    return Response(
-        render_template(
+    return render_to_response(
             request, 'mediagoblin/user_pages/media.html',
-            {'media': media}))
+            {'media': media})
 
 
 ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 5
index 3649b6c30711ad1f3cd893a44ce367ed57e1e2a8..f69c91f26a576ef24633e179655c0ddc7df01b35 100644 (file)
@@ -29,6 +29,7 @@ from babel.localedata import exists
 import jinja2
 import translitcodec
 from paste.deploy.loadwsgi import NicerConfigParser
+from webob import Response
 
 from mediagoblin import globals as mgoblin_globals
 from mediagoblin.db.util import ObjectId
@@ -117,6 +118,11 @@ def clear_test_template_context():
     TEMPLATE_TEST_CONTEXT = {}
 
 
+def render_to_response(request, template, context):
+    """Much like Django's shortcut.render()"""
+    return Response(render_template(request, template, context))
+
+
 def setup_user_in_request(request):
     """
     Examine a request and tack on a request.user parameter if that's
index ee0b520aac40a2e22ffa815aed100023585f3b68..dc2d45ba7ce51dc6dd130a2bb0e4efd2b8319521 100644 (file)
 # 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
-
-from mediagoblin.util import render_template
+from mediagoblin.util import render_to_response
 from mediagoblin.db.util import DESCENDING
 
 def root_view(request):
     media_entries = request.db.MediaEntry.find(
         {u'state': u'processed'}).sort('created', DESCENDING)
     
-    return Response(
-        render_template(
+    return render_to_response(
             request, 'mediagoblin/root.html',
-             {'media_entries': media_entries}))
+             {'media_entries': media_entries})