aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools/response.py
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2012-11-29 15:27:50 +0100
committerElrond <elrond+mediagoblin.org@samba-tng.org>2012-11-29 15:27:50 +0100
commite4f33f4093f6a141bfc4802911c5fd77327112ad (patch)
treebd19bc4ed167392d3e77cea9542b0a49efe970fe /mediagoblin/tools/response.py
parent6adcea2451519d1276e989ac200df8ed43954c48 (diff)
parent26c71029b44d4384020b2f928fb18f59b1d1356b (diff)
downloadmediagoblin-e4f33f4093f6a141bfc4802911c5fd77327112ad.tar.lz
mediagoblin-e4f33f4093f6a141bfc4802911c5fd77327112ad.tar.xz
mediagoblin-e4f33f4093f6a141bfc4802911c5fd77327112ad.zip
Merge remote-tracking branch 'spaetz/formerge/538_FORBIDDEN_admin_pages'
* spaetz/formerge/538_FORBIDDEN_admin_pages: Fix error page text Return code 403 when accessing admin pages Implement generic error pages
Diffstat (limited to 'mediagoblin/tools/response.py')
-rw-r--r--mediagoblin/tools/response.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/mediagoblin/tools/response.py b/mediagoblin/tools/response.py
index a54c32fb..6d14b8b7 100644
--- a/mediagoblin/tools/response.py
+++ b/mediagoblin/tools/response.py
@@ -16,6 +16,7 @@
from webob import Response, exc
from mediagoblin.tools.template import render_template
+from mediagoblin.tools.translate import fake_ugettext_passthrough as _
def render_to_response(request, template, context, status=200):
@@ -25,14 +26,34 @@ def render_to_response(request, template, context, status=200):
status=status)
-def render_404(request):
- """
- Render a 404.
+def render_error(request, status=500, title=_('Oops!'),
+ err_msg=_('An error occured')):
+ """Render any error page with a given error code, title and text body
+
+ Title and description are passed through as-is to allow html. Make
+ sure no user input is contained therein for security reasons. The
+ description will be wrapped in <p></p> tags.
"""
- return render_to_response(
- request, 'mediagoblin/404.html', {}, status=404)
+ return Response(render_template(request, 'mediagoblin/error.html',
+ {'err_code': status, 'title': title, 'err_msg': err_msg}),
+ status=status)
+def render_403(request):
+ """Render a standard 403 page"""
+ title = _('Operation not allowed')
+ err_msg = _("Sorry Dave, I can't let you do that!</p><p>You have tried "
+ " to perform a function that you are not allowed to. Have you "
+ "been trying to delete all user accounts again?")
+ return render_error(request, 403, title, err_msg)
+
+def render_404(request):
+ """Render a standard 404 page."""
+ err_msg = _("There doesn't seem to be a page at this address. Sorry!</p>"
+ "<p>If you're sure the address is correct, maybe the page "
+ "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"""