Remove specialized middleware to show custom 403 error, not needed with recent Django versions.

This commit is contained in:
Roberto Rosario
2015-06-29 16:57:20 -04:00
parent 5be41af1cf
commit cbfc840466
7 changed files with 34 additions and 62 deletions

View File

@@ -0,0 +1,14 @@
{% extends 'appearance/base.html' %}
{% load i18n %}
{% block title %} :: {% blocktrans %}Insufficient permissions{% endblocktrans %}{% endblock %}
{% block content %}
<div class="content">
<h3 class="title">{% blocktrans %}Insufficient permissions{% endblocktrans %}</h3>
<div class="inner">
<p>{% blocktrans %}You don't have enough permissions for this operation.{% endblocktrans %}</p>
</div>
</div>
{% endblock %}

View File

@@ -6,7 +6,7 @@
{% block content %}
<div class="content">
<h2 class="title">{% blocktrans %}Page not found{% endblocktrans %}</h2>
<h3 class="title">{% blocktrans %}Page not found{% endblocktrans %}</h3>
<div class="inner">
<p>{% blocktrans %}Sorry, but the requested page could not be found.{% endblocktrans %}</p>
</div>

View File

@@ -0,0 +1,19 @@
{% extends 'appearance/base.html' %}
{% load i18n %}
{% block title %} :: {% trans 'Server error' %}{% endblock %}
{% block content %}
<div class="content">
<h3 class="title">{% trans 'Server error' %}</h3>
<div class="inner">
<p>{% trans "There's been an error. It's been reported to the site administrators via e-mail and should be fixed shortly. Thanks for your patience." %}</p>
{% if request.sentry.id %}
<p>{% trans 'If you need assistance, you may reference this error via the following identifier:' %}</p>
<p><strong>{{ request.sentry.id }}</strong></p>
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -1,19 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Page unavailable</title>
</head>
<body>
<h1>Page unavailable</h1>
<p>Sorry, but the requested page is unavailable due to a server problem.</p>
<p>Administrators have been notified, so check back later.</p>
{% if request.sentry.id %}
<p>If you need assistance, you may reference this error as
<strong>{{ request.sentry.id }}</strong>.</p>
{% endif %}
</body>
</html>

View File

@@ -1,41 +0,0 @@
from __future__ import unicode_literals
from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.http import HttpResponseForbidden
from django.template import RequestContext, Template, loader, TemplateDoesNotExist
from django.utils.importlib import import_module
# http://mitchfournier.com/2010/07/12/show-a-custom-403-forbidden-error-page-in-django/
class PermissionDeniedMiddleware(object):
def process_exception(self, request, exception):
if isinstance(exception, PermissionDenied):
try:
# Handle import error but allow any type error from view
callback = getattr(import_module(settings.ROOT_URLCONF), 'handler403')
return callback(request, exception)
except (ImportError, AttributeError):
# Try to get a 403 template
try:
# First look for a user-defined template named "403.html"
t = loader.get_template('403.html')
except TemplateDoesNotExist:
# If a template doesn't exist in the projct, use the following hardcoded template
t = Template('''{% load i18n %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>{% trans "403 ERROR: Access denied" %}</title>
</head>
<body>
<h1>{% trans "Access Denied (403)" %}</h1>
{% trans "We're sorry, but you are not authorized to view this page." %}
</body>
</html>''')
# Now use context and render template
c = RequestContext(request)
return HttpResponseForbidden(t.render(c))

View File

@@ -114,7 +114,6 @@ MIDDLEWARE_CLASSES = (
'common.middleware.timezone.TimezoneMiddleware',
'common.middleware.strip_spaces_widdleware.SpacelessMiddleware',
'authentication.middleware.login_required_middleware.LoginRequiredMiddleware',
'permissions.middleware.permission_denied_middleware.PermissionDeniedMiddleware',
'pagination.middleware.PaginationMiddleware',
'common.middleware.ajax_redirect.AjaxRedirect',
)