diff options
author | Mike Linksvayer <ml@gondwanaland.com> | 2012-12-20 12:50:43 -0800 |
---|---|---|
committer | Mike Linksvayer <ml@gondwanaland.com> | 2012-12-20 12:50:43 -0800 |
commit | 1d0148aef1493467dacb6c39c4e080ee4a5246d2 (patch) | |
tree | 5213418660d4e079eb8dac6bc8ea2e4fdc140088 /mediagoblin/tools/response.py | |
parent | 200433dc38a2139462e0331be36ee49a80a81a12 (diff) | |
parent | 5c99cd01a70f2d597ac7669e8d944ddf79b05281 (diff) | |
download | mediagoblin-1d0148aef1493467dacb6c39c4e080ee4a5246d2.tar.lz mediagoblin-1d0148aef1493467dacb6c39c4e080ee4a5246d2.tar.xz mediagoblin-1d0148aef1493467dacb6c39c4e080ee4a5246d2.zip |
Merge branch 'master' of git://gitorious.org/mediagoblin/mediagoblin
Conflicts:
docs/source/siteadmin/media-types.rst
Diffstat (limited to 'mediagoblin/tools/response.py')
-rw-r--r-- | mediagoblin/tools/response.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/mediagoblin/tools/response.py b/mediagoblin/tools/response.py index a54c32fb..81939a77 100644 --- a/mediagoblin/tools/response.py +++ b/mediagoblin/tools/response.py @@ -16,6 +16,8 @@ from webob import Response, exc from mediagoblin.tools.template import render_template +from mediagoblin.tools.translate import (lazy_pass_to_ugettext as _, + pass_to_ugettext) def render_to_response(request, template, context, status=200): @@ -25,14 +27,36 @@ 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""" + _ = pass_to_ugettext + 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.""" + _ = pass_to_ugettext + 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""" |