Skip to content

Instantly share code, notes, and snippets.

@specialunderwear
Created August 4, 2010 08:35
Show Gist options
  • Save specialunderwear/507847 to your computer and use it in GitHub Desktop.
Save specialunderwear/507847 to your computer and use it in GitHub Desktop.
# 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