mirror of
https://github.com/jazzband/django-authority.git
synced 2026-03-16 22:20:28 +00:00
Features removed in 1.9 :
1. All models need to be defined inside an installed application or declare an explicit app_label. Furthermore, it isn’t possible to import them before their application is loaded. In particular, it isn’t possible to import models inside the root package of an application 2. The django.contrib.contenttypes.generic module is removed 3. django.db.models.loading is removed.
This commit is contained in:
parent
1cef19d7de
commit
91929a76c9
8 changed files with 42 additions and 33 deletions
|
|
@ -1,8 +1,3 @@
|
|||
import sys
|
||||
|
||||
from authority.sites import site, get_check, get_choices_for, register, unregister # noqa
|
||||
|
||||
|
||||
LOADING = False
|
||||
|
||||
|
||||
|
|
@ -16,19 +11,5 @@ def autodiscover():
|
|||
return
|
||||
LOADING = True
|
||||
|
||||
import imp
|
||||
from django.conf import settings
|
||||
|
||||
for app in settings.INSTALLED_APPS:
|
||||
try:
|
||||
__import__(app)
|
||||
app_path = sys.modules[app].__path__
|
||||
except AttributeError:
|
||||
continue
|
||||
try:
|
||||
imp.find_module('permissions', app_path)
|
||||
except ImportError:
|
||||
continue
|
||||
__import__("%s.permissions" % app)
|
||||
app_path = sys.modules["%s.permissions" % app]
|
||||
LOADING = False
|
||||
from authority import utils
|
||||
utils.autodiscover_modules()
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from django.utils.safestring import mark_safe
|
|||
from django.forms.formsets import all_valid
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin import helpers
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.contenttypes.admin import GenericTabularInline
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
|
|
@ -22,10 +22,10 @@ except ImportError:
|
|||
|
||||
from authority.models import Permission
|
||||
from authority.widgets import GenericForeignKeyRawIdWidget
|
||||
from authority import get_choices_for
|
||||
from authority.utils import get_choices_for
|
||||
|
||||
|
||||
class PermissionInline(generic.GenericTabularInline):
|
||||
class PermissionInline(GenericTabularInline):
|
||||
model = Permission
|
||||
raw_id_fields = ('user', 'group', 'creator')
|
||||
extra = 1
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ import inspect
|
|||
from django.http import HttpResponseRedirect
|
||||
from django.utils.http import urlquote
|
||||
from django.utils.functional import wraps
|
||||
from django.db.models import Model, get_model
|
||||
from django.db.models import Model
|
||||
from django.apps import apps
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import REDIRECT_FIELD_NAME
|
||||
|
||||
from authority import get_check
|
||||
from authority.utils import get_check
|
||||
from authority.views import permission_denied
|
||||
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ def permission_required(perm, *lookup_variables, **kwargs):
|
|||
if value is None:
|
||||
continue
|
||||
if isinstance(model, basestring):
|
||||
model_class = get_model(*model.split("."))
|
||||
model_class = apps.get_model(*model.split("."))
|
||||
else:
|
||||
model_class = model
|
||||
if model_class is None:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ from django.contrib.contenttypes.models import ContentType
|
|||
from django.contrib.auth.models import Group
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from authority import permissions, get_choices_for
|
||||
from authority import permissions
|
||||
from authority.utils import get_choices_for
|
||||
from authority.models import Permission
|
||||
from authority.compat import get_user_model
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from datetime import datetime
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
from django.contrib.auth.models import Group
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ class Permission(models.Model):
|
|||
codename = models.CharField(_('codename'), max_length=100)
|
||||
content_type = models.ForeignKey(ContentType, related_name="row_permissions")
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||
content_object = GenericForeignKey('content_type', 'object_id')
|
||||
|
||||
user = models.ForeignKey(
|
||||
user_model_label, null=True, blank=True, related_name='granted_permissions')
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
|
||||
from authority import get_check
|
||||
from authority.utils import get_check
|
||||
from authority import permissions
|
||||
from authority.compat import get_user_model
|
||||
from authority.models import Permission
|
||||
|
|
|
|||
26
authority/utils.py
Normal file
26
authority/utils.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import sys
|
||||
|
||||
from authority.sites import site, get_check, get_choices_for, register, unregister # noqa
|
||||
|
||||
|
||||
def autodiscover_modules():
|
||||
"""
|
||||
Goes and imports the permissions submodule of every app in INSTALLED_APPS
|
||||
to make sure the permission set classes are registered correctly.
|
||||
"""
|
||||
import imp
|
||||
from django.conf import settings
|
||||
|
||||
for app in settings.INSTALLED_APPS:
|
||||
try:
|
||||
__import__(app)
|
||||
app_path = sys.modules[app].__path__
|
||||
except AttributeError:
|
||||
continue
|
||||
try:
|
||||
imp.find_module('permissions', app_path)
|
||||
except ImportError:
|
||||
continue
|
||||
__import__("%s.permissions" % app)
|
||||
app_path = sys.modules["%s.permissions" % app]
|
||||
LOADING = False
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.http import HttpResponseRedirect, HttpResponseForbidden
|
||||
from django.db.models.loading import get_model
|
||||
from django.apps import apps
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.template.context import RequestContext
|
||||
from django.template import loader
|
||||
|
|
@ -26,7 +26,7 @@ def add_permission(request, app_label, module_name, pk, approved=False,
|
|||
template_name='authority/permission_form.html',
|
||||
extra_context=None, form_class=UserPermissionForm):
|
||||
codename = request.POST.get('codename', None)
|
||||
model = get_model(app_label, module_name)
|
||||
model = apps.get_model(app_label, module_name)
|
||||
if model is None:
|
||||
return permission_denied(request)
|
||||
obj = get_object_or_404(model, pk=pk)
|
||||
|
|
|
|||
Loading…
Reference in a new issue