# 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
    return perms + opts.permissions

#code => <collection>.code
#lookup code => dockit.<collection>.code
#content type = DockitPermission

#user.has_perm(dockit.somecollection.code)

def create_permissions(documents, verbosity, **kwargs):
    # This will hold the permissions we're looking for as
    # (content_type, (codename, name))
    searched_perms = list()
    ctype = ContentType.objects.get_for_model(DockitPermission)
    # The codenames and ctypes that should exist.
    for klass in documents:
        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:

# 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

    return perms + opts.permissions

#code => <collection>.code
#lookup code => dockit.<collection>.code
#content type = DockitPermission

#user.has_perm(dockit.somecollection.code)

def create_permissions(documents, verbosity, **kwargs):
    # This will hold the permissions we're looking for as
    # (content_type, (codename, name))
    searched_perms = list()
    ctype = ContentType.objects.get_for_model(DockitPermission)
    # The codenames and ctypes that should exist.
    for klass in documents:
        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