# 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


def _get_permission_codename(action, opts):
    return u'%s.%s' % (opts.collection, action)

def _get_all_permissions(opts):
    "Returns (codename, name) for all permissions in the given opts."
    perms = []
    for action in ('add', 'change', 'delete'):
        perms.append((_get_permission_codename(action, opts), u'Can %s %s' % (action, opts.verbose_name_raw)))
    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()

# 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



def _get_permission_codename(action, opts):
    return u'%s.%s' % (opts.collection, action)

def _get_all_permissions(opts):
    "Returns (codename, name) for all permissions in the given opts."
    perms = []
    for action in ('add', 'change', 'delete'):
        perms.append((_get_permission_codename(action, opts), u'Can %s %s' % (action, opts.verbose_name_raw)))
    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)