display 403 error page if user has no admin privileges

Closes #6397
This commit is contained in:
Serghei Mihai 2015-02-02 18:05:34 +01:00
parent f7dcd7b09b
commit 8d45681fd8
2 changed files with 15 additions and 1 deletions

8
hobo/templates/403.html Normal file
View File

@ -0,0 +1,8 @@
{% extends "hobo/base.html" %}
{% load i18n %}
{% block content %}
<h4>
{% trans "You have no permission to access this page" %}
</h4>
{% endblock %}

View File

@ -4,13 +4,19 @@ from django.http import HttpResponse
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic import edit from django.views.generic import edit
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import user_passes_test from django.contrib.auth.decorators import user_passes_test
from .environment.utils import Zone, get_operational_services from .environment.utils import Zone, get_operational_services
from .forms import HoboForm, HoboUpdateForm, get_tenant_model from .forms import HoboForm, HoboUpdateForm, get_tenant_model
admin_required = user_passes_test(lambda u: u.is_superuser) def is_superuser(u):
if not u.is_superuser:
raise PermissionDenied
return True
admin_required = user_passes_test(is_superuser)
class Home(TemplateView): class Home(TemplateView):
template_name = 'hobo/home.html' template_name = 'hobo/home.html'