# Path: dockit/models.py
# class DockitPermission(models.Model):
#     pass #a content type is required for creating permissions
# 
# Path: dockit/schema/signals.py

# 
# Path: dockit/schema/loading.py
# def get_documents(self, app_label=None):
#     if self.pending_documents and self.app_cache_ready():
#         self.post_app_ready()
#     if app_label:
#         return self.app_documents[app_label].values()
#     return self.documents.values()


from dockit.models import DockitPermission
from dockit.schema.signals import document_registered
from dockit.schema.loading import get_documents
from django.contrib.auth import models as auth_app
from django.contrib.contenttypes.models import ContentType
from django.db.utils import DatabaseError
from django.db.transaction import commit_on_success
        for perm in _get_all_permissions(klass._meta):
            searched_perms.append(perm)

    # Find all the Permissions that have a context_type for a model we're
    # looking for.  We don't need to check for codenames since we already have
    # a list of the ones we're going to create.
    all_perms = set(auth_app.Permission.objects.filter(
        content_type=ctype,
    ).values_list(
        "codename", flat=True
    ))
    
    for codename, name in searched_perms:
        # If the permissions exists, move on.
        if codename in all_perms:
            continue
        p = auth_app.Permission.objects.create(
            codename=codename,
            name=name,
            content_type=ctype
        )
        if verbosity >= 2:
            print "Adding permission '%s'" % p

def on_document_registered(document, **kwargs):
    create_permissions([document], 1)
document_registered.connect(on_document_registered)

try:
    #wrap with commit_on_success as to try to not poison a higher transaction

# Path: dockit/models.py
# class DockitPermission(models.Model):
#     pass #a content type is required for creating permissions
# 
# Path: dockit/schema/signals.py

# 
# Path: dockit/schema/loading.py
# def get_documents(self, app_label=None):
#     if self.pending_documents and self.app_cache_ready():
#         self.post_app_ready()
#     if app_label:
#         return self.app_documents[app_label].values()
#     return self.documents.values()


# Path: dockit/auth.py
from dockit.models import DockitPermission
from dockit.schema.signals import document_registered
from dockit.schema.loading import get_documents
from django.contrib.auth import models as auth_app
from django.contrib.contenttypes.models import ContentType
from django.db.utils import DatabaseError
from django.db.transaction import commit_on_success

        for perm in _get_all_permissions(klass._meta):
            searched_perms.append(perm)

    # Find all the Permissions that have a context_type for a model we're
    # looking for.  We don't need to check for codenames since we already have
    # a list of the ones we're going to create.
    all_perms = set(auth_app.Permission.objects.filter(
        content_type=ctype,
    ).values_list(
        "codename", flat=True
    ))
    
    for codename, name in searched_perms:
        # If the permissions exists, move on.
        if codename in all_perms:
            continue
        p = auth_app.Permission.objects.create(
            codename=codename,
            name=name,
            content_type=ctype
        )
        if verbosity >= 2:
            print "Adding permission '%s'" % p

def on_document_registered(document, **kwargs):
    create_permissions([document], 1)
document_registered.connect(on_document_registered)

try:
    #wrap with commit_on_success as to try to not poison a higher transaction

    commit_on_success(create_permissions)(get_documents(), 1)