Source

django-extauth / extauth / auth / management / __init__.py

Michael Hall ec89597 






























'''
Created on Mar 25, 2010

@author: hallmj
'''

from django.db.models import get_models, signals
from django.contrib.auth import models as auth_app
from django.db.models import get_apps, get_models, signals

def create_roles(app, created_models, verbosity, **kwargs):
    from django.contrib.contenttypes.models import ContentType
    from django.contrib.auth.models import Permission
    from extauth.auth.models import Role
    from extauth.auth import roles
    roles.autodiscover()
    
    if not roles.registered_roles:
        return
    for klass in roles.registered_roles.keys():
        ctype = ContentType.objects.get_for_model(klass)
        rm = roles.get_rolemanager(klass)
        
        for rName in rm._roles:
            r, created = Role.objects.get_or_create(role=rName, model__pk=ctype.id,
                defaults={'model': ctype})
            if created and verbosity >= 2:
                print "Adding role '%s'" % r

signals.post_syncdb.connect(create_roles,
    dispatch_uid = "extauth.auth.management.create_roles")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.