diff --git a/mediagoblin/templates/mediagoblin/404.html b/mediagoblin/templates/mediagoblin/error.html
similarity index 70%
rename from mediagoblin/templates/mediagoblin/404.html
rename to mediagoblin/templates/mediagoblin/error.html
index c0fe8b62..c16b650f 100644
--- a/mediagoblin/templates/mediagoblin/404.html
+++ b/mediagoblin/templates/mediagoblin/error.html
@@ -17,15 +17,12 @@
#}
{% extends "mediagoblin/base.html" %}
-{% block title %}404 — {{ super() }}{% endblock %}
+{% block title %}{{err_code}} — {{ super() }}{% endblock %}
{% block mediagoblin_content %}
-
{% trans %}There doesn't seem to be a page at this address. Sorry!{% endtrans %}
-- {%- trans %}If you're sure the address is correct, maybe the page you're looking for has been moved or deleted.{% endtrans -%} -
+ alt="{% trans %}Image of goblin stressing out{% endtrans %}" /> +{{ err_msg|safe }}
{% endblock %} diff --git a/mediagoblin/tools/response.py b/mediagoblin/tools/response.py index a54c32fb..a77f68b9 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,13 +26,33 @@ def render_to_response(request, template, context, status=200): status=status) -def render_404(request): - """ - Render a 404. - """ - return render_to_response( - request, 'mediagoblin/404.html', {}, status=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 atag. + """ + 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!
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!
" + "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"""