Browse Source

added more custom error pages

php2python
Holger Frey 7 years ago
parent
commit
f74918b058
  1. 21
      ordr2/templates/errors/bad_csrf_token.jinja2
  2. 20
      ordr2/templates/errors/exception.jinja2
  3. 27
      ordr2/views/errors.py

21
ordr2/templates/errors/bad_csrf_token.jinja2

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
{% extends "ordr2:templates/layout.jinja2" %}
{% block subtitle %} Whoops! {% endblock subtitle %}
{% block content %}
<div class="content">
<div class="container">
<div class="row">
<div class="span12">
<hgroup id="access-denied">
<h1>Please try again.</h1>
<p class="info">There was a problem with your form submission.</p>
<p class="info">Maybe it took you too long to fill out the form.</p>
</hgroup>
</div>
</div>
</div>
</div>
{% endblock content %}

20
ordr2/templates/errors/exception.jinja2

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
{% extends "ordr2:templates/layout.jinja2" %}
{% block subtitle %} Whoops! {% endblock subtitle %}
{% block content %}
<div class="content">
<div class="container">
<div class="row">
<div class="span12">
<hgroup id="access-denied">
<h1>Whoops!</h1>
<p class="info">This really shouldn't happen - You encountered a bug.</p>
</hgroup>
</div>
</div>
</div>
</div>
{% endblock content %}

27
ordr2/views/errors.py

@ -1,6 +1,11 @@ @@ -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): @@ -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 {}