Add docstrings for almost all models
Also adds docstring to some managers and model methods. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -19,6 +19,12 @@ from .search import cabinet_search # NOQA
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Cabinet(MPTTModel):
|
||||
"""
|
||||
Model to store a hierarchical tree of document containers. Each container
|
||||
can store an unlimited number of documents using an M2M field. Only
|
||||
the top level container is can have an ACL. All child container's
|
||||
access is delegated to their corresponding root container.
|
||||
"""
|
||||
parent = TreeForeignKey(
|
||||
blank=True, db_index=True, null=True, on_delete=models.CASCADE,
|
||||
related_name='children', to='self'
|
||||
@@ -41,6 +47,10 @@ class Cabinet(MPTTModel):
|
||||
return self.get_full_path()
|
||||
|
||||
def add_document(self, document, user=None):
|
||||
"""
|
||||
Add a document to a container. This can be done without using this
|
||||
method but this method provides the event commit already coded.
|
||||
"""
|
||||
self.documents.add(document)
|
||||
event_cabinets_add_document.commit(
|
||||
action_object=self, actor=user, target=document
|
||||
@@ -50,14 +60,26 @@ class Cabinet(MPTTModel):
|
||||
return reverse('cabinets:cabinet_view', args=(self.pk,))
|
||||
|
||||
def get_document_count(self, user):
|
||||
"""
|
||||
Return numeric count of the total documents in a cabinet. The count
|
||||
is filtered by access.
|
||||
"""
|
||||
return self.get_documents_queryset(user=user).count()
|
||||
|
||||
def get_documents_queryset(self, user):
|
||||
"""
|
||||
Provide a queryset of the documents in a cabinet. The queryset is
|
||||
filtered by access.
|
||||
"""
|
||||
return AccessControlList.objects.filter_by_access(
|
||||
permission_document_view, user, queryset=self.documents
|
||||
)
|
||||
|
||||
def get_full_path(self):
|
||||
"""
|
||||
Returns a string that represents the path to the cabinet. The
|
||||
path string starts from the root cabinet.
|
||||
"""
|
||||
result = []
|
||||
for node in self.get_ancestors(include_self=True):
|
||||
result.append(node.label)
|
||||
@@ -65,17 +87,22 @@ class Cabinet(MPTTModel):
|
||||
return ' / '.join(result)
|
||||
|
||||
def remove_document(self, document, user=None):
|
||||
"""
|
||||
Remove a document from a cabinet. This method provides the
|
||||
corresponding event commit.
|
||||
"""
|
||||
self.documents.remove(document)
|
||||
event_cabinets_remove_document.commit(
|
||||
action_object=self, actor=user, target=document
|
||||
)
|
||||
|
||||
def validate_unique(self, exclude=None):
|
||||
# Explicit validation of uniqueness of parent+label as the provided
|
||||
# unique_together check in Meta is not working for all 100% cases
|
||||
# when there is a FK in the unique_together tuple
|
||||
# https://code.djangoproject.com/ticket/1751
|
||||
|
||||
"""
|
||||
Explicit validation of uniqueness of parent+label as the provided
|
||||
unique_together check in Meta is not working for all 100% cases
|
||||
when there is a FK in the unique_together tuple
|
||||
https://code.djangoproject.com/ticket/1751
|
||||
"""
|
||||
with transaction.atomic():
|
||||
if connection.vendor == 'oracle':
|
||||
queryset = Cabinet.objects.filter(parent=self.parent, label=self.label)
|
||||
@@ -102,6 +129,11 @@ class Cabinet(MPTTModel):
|
||||
|
||||
|
||||
class DocumentCabinet(Cabinet):
|
||||
"""
|
||||
Represent a document's cabinet. This Model is a proxy model from Cabinet
|
||||
and is used as an alias to map columns to it without having to map them
|
||||
to the base Cabinet model.
|
||||
"""
|
||||
class Meta:
|
||||
proxy = True
|
||||
verbose_name = _('Document cabinet')
|
||||
|
||||
Reference in New Issue
Block a user