Created
August 4, 2010 08:35
-
-
Save specialunderwear/507847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this file is in a package named verboten | |
from django.utils.translation import ugettext_lazy as _ | |
from django.http import HttpResponseForbidden | |
from django.template import RequestContext, loader | |
from django.db import models | |
from django.conf import settings | |
class LanguagePermissions(models.Model): | |
"""Only used to define permissions""" | |
class Meta: | |
permissions = settings.LANGUAGES | |
class VerbotenMiddleWare(object): | |
"""If you don't have permissions, you can not enter!""" | |
def process_request(self, request): | |
language = request.LANGUAGE_CODE | |
if request.user.is_authenticated(): | |
if not request.user.has_perm("verboten.%s" % language): | |
t = loader.get_template("admin/403.html") | |
request.user.message_set.create(message=_("You don't have permission to edit %s") % language) | |
return HttpResponseForbidden(t.render(RequestContext(request))) | |
return None | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment