From 77d58da1483758b655e7f33f12a2edb1c8e96cbc Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Wed, 27 Sep 2017 11:24:35 +0200 Subject: [PATCH] reworked error views --- ordr2/templates/404.jinja2 | 8 -------- ordr2/templates/errors/forbidden.jinja2 | 18 ++++++++++++++++++ ordr2/templates/errors/not_found.jinja2 | 18 ++++++++++++++++++ ordr2/views/errors.py | 18 ++++++++++++++++++ ordr2/views/notfound.py | 7 ------- 5 files changed, 54 insertions(+), 15 deletions(-) delete mode 100644 ordr2/templates/404.jinja2 create mode 100644 ordr2/templates/errors/forbidden.jinja2 create mode 100644 ordr2/templates/errors/not_found.jinja2 create mode 100644 ordr2/views/errors.py delete mode 100644 ordr2/views/notfound.py diff --git a/ordr2/templates/404.jinja2 b/ordr2/templates/404.jinja2 deleted file mode 100644 index 1917f83..0000000 --- a/ordr2/templates/404.jinja2 +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "layout.jinja2" %} - -{% block content %} -
-

Pyramid Alchemy scaffold

-

404 Page Not Found

-
-{% endblock content %} diff --git a/ordr2/templates/errors/forbidden.jinja2 b/ordr2/templates/errors/forbidden.jinja2 new file mode 100644 index 0000000..d221f77 --- /dev/null +++ b/ordr2/templates/errors/forbidden.jinja2 @@ -0,0 +1,18 @@ +{% extends "ordr2:templates/layout.jinja2" %} + +{% block subtitle %} Access Denied {% endblock subtitle %} + +{% block content %} +
+
+ +
+
+

Access Denied!!!

+

You do not have the permission to access this page.

+
+
+ +
+
+{% endblock content %} diff --git a/ordr2/templates/errors/not_found.jinja2 b/ordr2/templates/errors/not_found.jinja2 new file mode 100644 index 0000000..0beb0b2 --- /dev/null +++ b/ordr2/templates/errors/not_found.jinja2 @@ -0,0 +1,18 @@ +{% extends "ordr2:templates/layout.jinja2" %} + +{% block subtitle %} Not Found {% endblock subtitle %} + +{% block content %} +
+
+ +
+
+

These are not the droids
you are looking for

+

Whatever you wanted to see was not found on this server.

+
+
+ +
+
+{% endblock content %} diff --git a/ordr2/views/errors.py b/ordr2/views/errors.py new file mode 100644 index 0000000..448ce52 --- /dev/null +++ b/ordr2/views/errors.py @@ -0,0 +1,18 @@ +from pyramid.view import ( + notfound_view_config, + forbidden_view_config + ) + + +@notfound_view_config(renderer='ordr2:templates/errors/not_found.jinja2') +def notfound_view(context, request): + context.nav_highlight = 'errors' + request.response.status = 404 + return {} + + +@forbidden_view_config(renderer='ordr2:templates/errors/forbidden.jinja2') +def forbidden_view(context, request): + request.response.status = 403 + context.nav_highlight = 'errors' + return {} diff --git a/ordr2/views/notfound.py b/ordr2/views/notfound.py deleted file mode 100644 index 9798e0c..0000000 --- a/ordr2/views/notfound.py +++ /dev/null @@ -1,7 +0,0 @@ -from pyramid.view import notfound_view_config - - -@notfound_view_config(renderer='../templates/404.jinja2') -def notfound_view(context, request): - request.response.status = 404 - return {}