-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf3cdc1
commit bf9bab3
Showing
7 changed files
with
38 additions
and
33 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ python: | |
env: | ||
- DJANGO=1.9 | ||
- DJANGO=1.8 | ||
- DJANGO=1.10 | ||
|
||
# install dependencies | ||
install: | ||
|
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,47 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.apps import AppConfig, apps | ||
from django.contrib import admin | ||
from django.apps import AppConfig | ||
from django.apps import apps as global_apps | ||
from django.db.models.signals import post_migrate | ||
|
||
from .admin import AdminViewPermissionAdminSite | ||
from .utils import django_version | ||
from .enums import DjangoVersion | ||
|
||
|
||
def update_permissions(sender, app_config, verbosity, apps=global_apps, **kwargs): | ||
settings_models = getattr(settings, 'ADMIN_VIEW_PERMISSION_MODELS', None) | ||
|
||
# TODO: Maybe look at the registry not in all models | ||
for app in apps.get_app_configs(): | ||
for model in app.get_models(): | ||
if settings_models or (settings_models is not None and len( | ||
settings_models) == 0): | ||
|
||
if django_version() == DjangoVersion.DJANGO_18: | ||
model_name = '%s.%s' %(model._meta.app_label, | ||
model._meta.object_name) | ||
elif django_version() > DjangoVersion.DJANGO_18: | ||
model_name = model._meta.label | ||
|
||
if model_name in settings_models: | ||
model._meta.permissions = ( | ||
('view_%s' % model._meta.model_name, | ||
'Can view %s' % model._meta.model_name),) | ||
else: | ||
model._meta.permissions = ( | ||
('view_%s' % model._meta.model_name, | ||
'Can view %s' % model._meta.model_name),) | ||
|
||
|
||
class AdminViewPermissionConfig(AppConfig): | ||
name = 'admin_view_permission' | ||
|
||
def ready(self): | ||
settings_models = getattr(settings, 'ADMIN_VIEW_PERMISSION_MODELS', | ||
None) | ||
|
||
if not isinstance(admin.site, AdminViewPermissionAdminSite): | ||
admin.site = AdminViewPermissionAdminSite('admin') | ||
admin.sites.site = admin.site | ||
|
||
# TODO: Maybe look at the registry not in all models | ||
for app in apps.get_app_configs(): | ||
for model in app.get_models(): | ||
if settings_models or (settings_models is not None and len( | ||
settings_models) == 0): | ||
|
||
if django_version() == DjangoVersion.DJANGO_18: | ||
model_name = '%s.%s' %(model._meta.app_label, | ||
model._meta.object_name) | ||
elif django_version() == DjangoVersion.DJANGO_19: | ||
model_name = model._meta.label | ||
|
||
if model_name in settings_models: | ||
model._meta.permissions = ( | ||
('view_%s' % model._meta.model_name, | ||
'Can view %s' % model._meta.model_name),) | ||
else: | ||
model._meta.permissions = ( | ||
('view_%s' % model._meta.model_name, | ||
'Can view %s' % model._meta.model_name),) | ||
post_migrate.connect(update_permissions) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class DjangoVersion(object): | ||
DJANGO_18, DJANGO_19 = range(0,2) | ||
DJANGO_18, DJANGO_19, DJANGO_110 = range(0,3) |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Django>=1.8,<1.10 | ||
Django>=1.8 |
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