From f74918b05822e2de0662dcb298a25f015c07fba5 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 5 Oct 2017 12:38:13 +0200 Subject: [PATCH] added more custom error pages --- ordr2/templates/errors/bad_csrf_token.jinja2 | 21 +++++++++++++++ ordr2/templates/errors/exception.jinja2 | 20 +++++++++++++++ ordr2/views/errors.py | 27 +++++++++++++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 ordr2/templates/errors/bad_csrf_token.jinja2 create mode 100644 ordr2/templates/errors/exception.jinja2 diff --git a/ordr2/templates/errors/bad_csrf_token.jinja2 b/ordr2/templates/errors/bad_csrf_token.jinja2 new file mode 100644 index 0000000..9a54485 --- /dev/null +++ b/ordr2/templates/errors/bad_csrf_token.jinja2 @@ -0,0 +1,21 @@ +{% extends "ordr2:templates/layout.jinja2" %} + +{% block subtitle %} Whoops! {% endblock subtitle %} + +{% block content %} +
+
+
+ +
+
+

Please try again.

+

There was a problem with your form submission.

+

Maybe it took you too long to fill out the form.

+
+
+ +
+
+
+{% endblock content %} diff --git a/ordr2/templates/errors/exception.jinja2 b/ordr2/templates/errors/exception.jinja2 new file mode 100644 index 0000000..ed45303 --- /dev/null +++ b/ordr2/templates/errors/exception.jinja2 @@ -0,0 +1,20 @@ +{% extends "ordr2:templates/layout.jinja2" %} + +{% block subtitle %} Whoops! {% endblock subtitle %} + +{% block content %} +
+
+
+ +
+
+

Whoops!

+

This really shouldn't happen - You encountered a bug.

+
+
+ +
+
+
+{% endblock content %} diff --git a/ordr2/views/errors.py b/ordr2/views/errors.py index 448ce52..b2ccf0e 100644 --- a/ordr2/views/errors.py +++ b/ordr2/views/errors.py @@ -1,6 +1,11 @@ +''' display error pages ''' + + +from pyramid.exceptions import BadCSRFToken from pyramid.view import ( notfound_view_config, - forbidden_view_config + forbidden_view_config, + view_config ) @@ -13,6 +18,26 @@ def notfound_view(context, request): @forbidden_view_config(renderer='ordr2:templates/errors/forbidden.jinja2') def forbidden_view(context, request): + context.nav_highlight = 'errors' request.response.status = 403 + return {} + + +@view_config( + context=BadCSRFToken, + renderer='ordr2:templates/errors/bad_csrf_token.jinja2' + ) +def bad_csrf_view(context, request): + context.nav_highlight = 'errors' + request.response.status = 400 + return {} + + +@view_config( + context=Exception, + renderer='ordr2:templates/errors/exception.jinja2' + ) +def exception_view(context, request): context.nav_highlight = 'errors' + request.response.status = 500 return {}