aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/util.py')
-rw-r--r--mediagoblin/util.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index cc426228..0b6428da 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -138,9 +138,11 @@ def clear_test_template_context():
TEMPLATE_TEST_CONTEXT = {}
-def render_to_response(request, template, context):
+def render_to_response(request, template, context, status=200):
"""Much like Django's shortcut.render()"""
- return Response(render_template(request, template, context))
+ return Response(
+ render_template(request, template, context),
+ status=status)
def redirect(request, *args, **kwargs):
@@ -346,8 +348,10 @@ def get_locale_from_request(request):
accept_lang_matches = request.accept_language.best_matches()
# Your routing can explicitly specify a target language
- if request.matchdict.has_key('locale'):
- target_lang = request.matchdict['locale']
+ matchdict = request.matchdict or {}
+
+ if matchdict.has_key('locale'):
+ target_lang = matchdict['locale']
elif request.session.has_key('target_lang'):
target_lang = request.session['target_lang']
# Pull the first acceptable language
@@ -660,3 +664,11 @@ def gridify_cursor(this_cursor, num_cols=5):
the number of columns in the list
"""
return gridify_list(list(this_cursor), num_cols)
+
+
+def render_404(request):
+ """
+ Render a 404.
+ """
+ return render_to_response(
+ request, 'mediagoblin/404.html', {}, status=400)