From 1c63ad5d352f5eb38a4d634b9aea84cbeee269a4 Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 5 Jun 2011 15:25:45 +0200 Subject: [PATCH] Create render_to_reponse and use it everywhere. Just a shortcut for Response(render_template(...)) --- mediagoblin/auth/views.py | 34 ++++++++++++++------------------- mediagoblin/edit/views.py | 9 ++++----- mediagoblin/submit/views.py | 14 ++++++-------- mediagoblin/user_pages/views.py | 14 ++++++-------- mediagoblin/util.py | 6 ++++++ mediagoblin/views.py | 9 +++------ 6 files changed, 39 insertions(+), 47 deletions(-) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 2d24328d..a5112299 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -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', {}) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 027a426c..ac286bec 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -15,9 +15,9 @@ # along with this program. If not, see . -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}) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 256f5be9..a51e14e6 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -17,10 +17,10 @@ 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', {}) diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 6ea3fe36..0442e736 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -14,9 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -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 diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 3649b6c3..f69c91f2 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -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 diff --git a/mediagoblin/views.py b/mediagoblin/views.py index ee0b520a..dc2d45ba 100644 --- a/mediagoblin/views.py +++ b/mediagoblin/views.py @@ -14,16 +14,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -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}) -- 2.25.1