Add permission post init to initialize signal handler and registry file

This commit is contained in:
Roberto Rosario
2012-09-07 02:17:31 -04:00
parent e886dfc724
commit 4c1bfd5f61
2 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
from __future__ import absolute_import
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.core.exceptions import ObjectDoesNotExist
def user_post_save(sender, instance, **kwargs):
from .settings import DEFAULT_ROLES
if kwargs.get('created', False):
for default_role in SETTING_DEFAULT_ROLES:
if isinstance(default_role, Role):
#If a model is passed, execute method
default_role.add_member(instance)
else:
#If a role name is passed, lookup the corresponding model
try:
role = Role.objects.get(name=default_role)
role.add_member(instance)
except ObjectDoesNotExist:
pass
def init_signal_handler():
post_save.connect(user_post_save, sender=User)

View File

@@ -0,0 +1,25 @@
from __future__ import absolute_import
from django.utils.translation import ugettext_lazy as _
from smart_settings import LocalScope
from .icons import icon_permissions
from .links import role_list
name = 'permissions'
label = _(u'Permissions')
description = _(u'Handles the permissions in a project.')
icon = icon_permissions
dependencies = ['app_registry', 'smart_settings']
settings=[
{
'name': 'DEFAULT_ROLES',
'default': [],
'description': _(u'A list of existing roles that are automatically assigned to newly created users'),
'scopes': [LocalScope()]
}
]
setup_links=[role_list]