Update cabinets and document_index api views docstrings. Update multi level docstrings as per Python best practices.

Signed-off-by: Michael Price <loneviking72@gmail.com>
This commit is contained in:
Michael Price
2018-03-14 21:39:14 -04:00
committed by Roberto Rosario
parent f44fbe5687
commit de65d96fe2
35 changed files with 40 additions and 227 deletions

View File

@@ -82,7 +82,6 @@ class AccessControlListViewTestCase(GenericDocumentViewTestCase):
Test creating a duplicate ACL entry: same object & role
Result: Should redirect to existing ACL for object + role combination
"""
acl = AccessControlList.objects.create(
content_object=self.document, role=self.role
)
@@ -110,7 +109,6 @@ class AccessControlListViewTestCase(GenericDocumentViewTestCase):
Test creating an ACL entry for an object with no model permissions.
Result: Should display a blank permissions list (not optgroup)
"""
self.login_user()
self.role.permissions.add(

View File

@@ -27,7 +27,6 @@ class APIDocumentCabinetListView(generics.ListAPIView):
"""
Returns a list of all the cabinets to which a document belongs.
"""
serializer_class = CabinetSerializer
filter_backends = (MayanObjectPermissionsFilter,)

View File

@@ -23,7 +23,6 @@ class CabinetAPITestCase(APITestCase):
"""
Test the cabinet API endpoints
"""
def setUp(self):
super(CabinetAPITestCase, self).setUp()

View File

@@ -9,7 +9,6 @@ def check_new_version_creation(sender, instance, **kwargs):
"""
Make sure that new version creation is allowed for this document
"""
NewVersionBlock = apps.get_model(
app_label='checkouts', model_name='NewVersionBlock'
)

View File

@@ -14,7 +14,6 @@ class SplitTimeDeltaWidget(forms.widgets.MultiWidget):
A Widget that splits a timedelta input into three <input type="text">
boxes.
"""
def __init__(self, attrs=None):
widgets = (
forms.widgets.NumberInput(

View File

@@ -195,7 +195,6 @@ class UserForm(forms.ModelForm):
"""
Form used to edit an user's mininal fields by the user himself
"""
class Meta:
fields = ('username', 'first_name', 'last_name', 'email')
model = get_user_model()
@@ -205,7 +204,6 @@ class UserForm_view(DetailForm):
"""
Form used to display an user's public details
"""
class Meta:
fields = (
'username', 'first_name', 'last_name', 'email', 'last_login',

View File

@@ -48,7 +48,6 @@ class ExtraContextMixin(object):
"""
Mixin that allows views to pass extra context to the template
"""
extra_context = {}
def get_extra_context(self):
@@ -64,7 +63,6 @@ class FormExtraKwargsMixin(object):
"""
Mixin that allows a view to pass extra keyword arguments to forms
"""
form_extra_kwargs = {}
def get_form_extra_kwargs(self):
@@ -123,7 +121,6 @@ class MultipleObjectMixin(object):
"""
Mixin that allows a view to work on a single or multiple objects
"""
model = None
object_permission = None
pk_list_key = 'id_list'
@@ -184,7 +181,6 @@ class ObjectActionMixin(object):
"""
Mixin that performs an user action to a queryset
"""
success_message = 'Operation performed on %(count)d object'
success_message_plural = 'Operation performed on %(count)d objects'

View File

@@ -83,7 +83,6 @@ def render_subtemplate(context, template_name, template_context):
Renders the specified template with the mixed parent and
subtemplate contexts
"""
new_context = Context(context.flatten())
new_context.update(Context(template_context))
return get_template(template_name).render(new_context.flatten())

View File

@@ -312,7 +312,6 @@ def multi_object_action_view(request):
Proxy view called first when using a multi object action, which
then redirects to the appropiate specialized view
"""
next = request.POST.get(
'next', request.GET.get(
'next', request.META.get(

View File

@@ -65,7 +65,6 @@ class TransformationManager(models.Manager):
as_classes == True returns the transformation classes from .classes
ready to be feed to the converter class
"""
content_type = ContentType.objects.get_for_model(obj)
transformations = self.filter(

View File

@@ -12,7 +12,6 @@ class YAMLValidator(object):
"""
Validates that the input is YAML compliant.
"""
def __call__(self, value):
value = value.strip()
try:

View File

@@ -56,7 +56,6 @@ class APIIndexNodeInstanceDocumentListView(generics.ListAPIView):
Returns a list of all the documents contained by a particular index node
instance.
"""
filter_backends = (MayanObjectPermissionsFilter,)
mayan_object_permissions = {'GET': (permission_document_view,)}
serializer_class = DocumentSerializer
@@ -105,7 +104,6 @@ class APIDocumentIndexListView(generics.ListAPIView):
"""
Returns a list of all the indexes to which a document belongs.
"""
filter_backends = (MayanObjectPermissionsFilter,)
mayan_object_permissions = {'GET': (permission_document_indexing_view,)}
serializer_class = IndexInstanceNodeSerializer

View File

@@ -291,7 +291,6 @@ class DocumentIndexNodeListView(SingleObjectListView):
"""
Show a list of indexes where the current document can be found
"""
object_permission = permission_document_indexing_view
object_permission_related = 'index'

View File

@@ -10,7 +10,6 @@ def get_instance_link(index_instance_node):
"""
Return an HTML anchor to an index node instance
"""
return mark_safe(
'<a href="{url}">{text}</a>'.format(
url=index_instance_node.get_absolute_url(),
@@ -45,7 +44,6 @@ def node_level(node):
"""
Render an indented tree like output for a specific node
"""
return mark_safe(
''.join(
[

View File

@@ -19,7 +19,6 @@ class Parser(object):
"""
Parser base class
"""
_registry = {}
@classmethod
@@ -110,7 +109,6 @@ class PopplerParser(Parser):
"""
PDF parser using the pdftotext execute from the poppler package
"""
def __init__(self):
self.pdftotext_path = setting_pdftotext_path.value
if not os.path.exists(self.pdftotext_path):

View File

@@ -35,7 +35,6 @@ class SignatureBaseModel(models.Model):
it will generate a unique signature ID. No two signature IDs are the same,
even when using the same key.
"""
document_version = models.ForeignKey(
DocumentVersion, editable=False, on_delete=models.CASCADE,
related_name='signatures', verbose_name=_('Document version')

View File

@@ -62,7 +62,6 @@ class APIWorkflowDocumentTypeList(generics.ListCreateAPIView):
"""
This view returns a list of document types that belong to a workflow.
"""
return self.get_workflow().document_types.all()
def get_serializer(self, *args, **kwargs):
@@ -96,7 +95,6 @@ class APIWorkflowDocumentTypeList(generics.ListCreateAPIView):
Retrieve the parent workflow of the workflow document type.
Perform custom permission and access check.
"""
if self.request.method == 'GET':
permission_required = permission_workflow_view
else:
@@ -488,7 +486,6 @@ class APIWorkflowInstanceLogEntryListView(generics.ListCreateAPIView):
Failing that, check for ACLs for any of the workflow's transitions.
Failing that, then raise PermissionDenied
"""
AccessControlList.objects.check_access(
permissions=permission_workflow_view, user=self.request.user,
obj=document

View File

@@ -381,7 +381,6 @@ class APIDocumentTypeDocumentListView(generics.ListAPIView):
"""
Returns a list of all the documents of a particular document type.
"""
filter_backends = (MayanObjectPermissionsFilter,)
mayan_object_permissions = {'GET': (permission_document_view,)}
serializer_class = DocumentSerializer

View File

@@ -166,7 +166,6 @@ class DocumentTypeSelectForm(forms.Form):
Form to select the document type of a document to be created, used
as form #1 in the document creation wizard
"""
def __init__(self, *args, **kwargs):
user = kwargs.pop('user', None)
logger.debug('user: %s', user)

View File

@@ -154,7 +154,6 @@ class Document(models.Model):
generated for each document. No two documents can ever have the same UUID.
This ID is generated automatically.
"""
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
document_type = models.ForeignKey(
DocumentType, on_delete=models.CASCADE, related_name='documents',

View File

@@ -119,7 +119,6 @@ class DocumentTestCase(BaseTestCase):
Test document type trashing policies. Documents are moved to the
trash, x amount of time after being uploaded
"""
self.document_type.trash_time_period = 1
# 'seconds' is not a choice via the model, used here for convenience
self.document_type.trash_time_unit = 'seconds'
@@ -142,7 +141,6 @@ class DocumentTestCase(BaseTestCase):
Test document type deletion policies. Documents are deleted from the
trash, x amount of time after being trashed
"""
self.document_type.delete_time_period = 1
# 'seconds' is not a choice via the model, used here for convenience
self.document_type.delete_time_unit = 'seconds'

View File

@@ -30,7 +30,6 @@ class DocumentSearchTestCase(BaseTestCase):
Test that simple search works after related_name changes to
document versions and document version pages
"""
queryset, elapsed_time = document_search.search(
{'q': 'Mayan'}, user=self.admin_user
)

View File

@@ -13,7 +13,6 @@ class Issue46TestCase(GenericViewTestCase):
"""
Functional tests to make sure issue 46 is fixed
"""
def setUp(self):
super(Issue46TestCase, self).setUp()
self.login_admin_user()

View File

@@ -28,13 +28,10 @@ from .serializers import (
class APIDocumentMetadataListView(generics.ListCreateAPIView):
def get(self, *args, **kwargs):
"""
Returns a list of selected document's metadata types and values.
get: Returns a list of selected document's metadata types and values.
post: Add an existing metadata type and value to the selected document.
"""
return super(APIDocumentMetadataListView, self).get(*args, **kwargs)
def get_document(self):
if self.request.method == 'GET':
permission_required = permission_metadata_document_view
@@ -81,31 +78,16 @@ class APIDocumentMetadataListView(generics.ListCreateAPIView):
return context
def post(self, *args, **kwargs):
"""
Add an existing metadata type and value to the selected document.
"""
return super(APIDocumentMetadataListView, self).post(*args, **kwargs)
class APIDocumentMetadataView(generics.RetrieveUpdateDestroyAPIView):
"""
delete: Remove this metadata entry from the selected document.
get: Return the details of the selected document metadata type and value.
patch: Edit the selected document metadata type and value.
put: Edit the selected document metadata type and value.
"""
lookup_url_kwarg = 'metadata_pk'
def delete(self, *args, **kwargs):
"""
Remove this metadata entry from the selected document.
"""
return super(APIDocumentMetadataView, self).delete(*args, **kwargs)
def get(self, *args, **kwargs):
"""
Return the details of the selected document metadata type and value.
"""
return super(APIDocumentMetadataView, self).get(*args, **kwargs)
def get_document(self):
if self.request.method == 'GET':
permission_required = permission_metadata_document_view
@@ -142,22 +124,12 @@ class APIDocumentMetadataView(generics.RetrieveUpdateDestroyAPIView):
else:
return DocumentMetadataSerializer
def patch(self, *args, **kwargs):
"""
Edit the selected document metadata type and value.
"""
return super(APIDocumentMetadataView, self).patch(*args, **kwargs)
def put(self, *args, **kwargs):
"""
Edit the selected document metadata type and value.
"""
return super(APIDocumentMetadataView, self).put(*args, **kwargs)
class APIMetadataTypeListView(generics.ListCreateAPIView):
"""
get: Returns a list of all the metadata types.
post: Create a new metadata type.
"""
filter_backends = (MayanObjectPermissionsFilter,)
mayan_object_permissions = {'GET': (permission_metadata_type_view,)}
mayan_view_permissions = {'POST': (permission_metadata_type_create,)}
@@ -165,22 +137,14 @@ class APIMetadataTypeListView(generics.ListCreateAPIView):
queryset = MetadataType.objects.all()
serializer_class = MetadataTypeSerializer
def get(self, *args, **kwargs):
"""
Returns a list of all the metadata types.
"""
return super(APIMetadataTypeListView, self).get(*args, **kwargs)
def post(self, *args, **kwargs):
"""
Create a new metadata type.
"""
return super(APIMetadataTypeListView, self).post(*args, **kwargs)
class APIMetadataTypeView(generics.RetrieveUpdateDestroyAPIView):
"""
delete: Delete the selected metadata type.
get: Return the details of the selected metadata type.
patch: Edit the selected metadata type.
put: Edit the selected metadata type.
"""
lookup_url_kwarg = 'metadata_type_pk'
mayan_object_permissions = {
'GET': (permission_metadata_type_view,),
@@ -192,47 +156,14 @@ class APIMetadataTypeView(generics.RetrieveUpdateDestroyAPIView):
queryset = MetadataType.objects.all()
serializer_class = MetadataTypeSerializer
def delete(self, *args, **kwargs):
"""
Delete the selected metadata type.
"""
return super(APIMetadataTypeView, self).delete(*args, **kwargs)
def get(self, *args, **kwargs):
"""
Return the details of the selected metadata type.
"""
return super(APIMetadataTypeView, self).get(*args, **kwargs)
def patch(self, *args, **kwargs):
"""
Edit the selected metadata type.
"""
return super(APIMetadataTypeView, self).patch(*args, **kwargs)
def put(self, *args, **kwargs):
"""
Edit the selected metadata type.
"""
return super(APIMetadataTypeView, self).put(*args, **kwargs)
class APIDocumentTypeMetadataTypeListView(generics.ListCreateAPIView):
"""
get: Returns a list of selected document type's metadata types.
post: Add a metadata type to the selected document type.
"""
lookup_url_kwarg = 'metadata_type_pk'
def get(self, *args, **kwargs):
"""
Returns a list of selected document type's metadata types.
"""
return super(
APIDocumentTypeMetadataTypeListView, self
).get(*args, **kwargs)
def get_document_type(self):
if self.request.method == 'GET':
permission_required = permission_document_type_view
@@ -279,38 +210,17 @@ class APIDocumentTypeMetadataTypeListView(generics.ListCreateAPIView):
return context
def post(self, *args, **kwargs):
"""
Add a metadata type to the selected document type.
"""
return super(
APIDocumentTypeMetadataTypeListView, self
).post(*args, **kwargs)
class APIDocumentTypeMetadataTypeView(generics.RetrieveUpdateDestroyAPIView):
"""
delete: Remove a metadata type from a document type.
get: Retrieve the details of a document type metadata type.
patch: Edit the selected document type metadata type.
put: Edit the selected document type metadata type.
"""
lookup_url_kwarg = 'metadata_type_pk'
serializer_class = DocumentTypeMetadataTypeSerializer
def delete(self, *args, **kwargs):
"""
Remove a metadata type from a document type.
"""
return super(
APIDocumentTypeMetadataTypeView, self
).delete(*args, **kwargs)
def get(self, *args, **kwargs):
"""
Retrieve the details of a document type metadata type.
"""
return super(
APIDocumentTypeMetadataTypeView, self
).get(*args, **kwargs)
def get_document_type(self):
if self.request.method == 'GET':
permission_required = permission_document_type_view
@@ -342,21 +252,3 @@ class APIDocumentTypeMetadataTypeView(generics.RetrieveUpdateDestroyAPIView):
return DocumentTypeMetadataTypeSerializer
else:
return WritableDocumentTypeMetadataTypeSerializer
def patch(self, *args, **kwargs):
"""
Edit the selected document type metadata type.
"""
return super(
APIDocumentTypeMetadataTypeView, self
).patch(*args, **kwargs)
def put(self, *args, **kwargs):
"""
Edit the selected document type metadata type.
"""
return super(
APIDocumentTypeMetadataTypeView, self
).put(*args, **kwargs)

View File

@@ -35,7 +35,6 @@ class MetadataType(models.Model):
"""
Define a type of metadata
"""
name = models.CharField(
max_length=48,
help_text=_(
@@ -149,7 +148,6 @@ class DocumentMetadata(models.Model):
Link a document to a specific instance of a metadata type with it's
current value
"""
document = models.ForeignKey(
Document, on_delete=models.CASCADE, related_name='metadata',
verbose_name=_('Document')

View File

@@ -100,7 +100,6 @@ class MetadataTestCase(MetadataTypeMixin, BaseTestCase):
Checks for GitLab issue #250
Empty optional lookup metadata trigger validation error
"""
self.metadata_type.lookup = TEST_LOOKUP_TEMPLATE
self.metadata_type.save()

View File

@@ -14,6 +14,10 @@ from .serializers import MessageSerializer
class APIMessageListView(generics.ListCreateAPIView):
"""
get: Returns a list of all the messages.
post: Create a new message.
"""
filter_backends = (MayanObjectPermissionsFilter,)
mayan_object_permissions = {'GET': (permission_message_view,)}
mayan_view_permissions = {'POST': (permission_message_create,)}
@@ -21,22 +25,14 @@ class APIMessageListView(generics.ListCreateAPIView):
queryset = Message.objects.all()
serializer_class = MessageSerializer
def get(self, *args, **kwargs):
"""
Returns a list of all the messages.
"""
return super(APIMessageListView, self).get(*args, **kwargs)
def post(self, *args, **kwargs):
"""
Create a new message.
"""
return super(APIMessageListView, self).post(*args, **kwargs)
class APIMessageView(generics.RetrieveUpdateDestroyAPIView):
"""
delete: Delete the selected message.
get: Return the details of the selected message.
patch: Edit the selected message.
put: Edit the selected message.
"""
filter_backends = (MayanObjectPermissionsFilter,)
mayan_object_permissions = {
'DELETE': (permission_message_delete,),
@@ -46,31 +42,3 @@ class APIMessageView(generics.RetrieveUpdateDestroyAPIView):
}
queryset = Message.objects.all()
serializer_class = MessageSerializer
def delete(self, *args, **kwargs):
"""
Delete the selected message.
"""
return super(APIMessageView, self).delete(*args, **kwargs)
def get(self, *args, **kwargs):
"""
Return the details of the selected message.
"""
return super(APIMessageView, self).get(*args, **kwargs)
def patch(self, *args, **kwargs):
"""
Edit the selected message.
"""
return super(APIMessageView, self).patch(*args, **kwargs)
def put(self, *args, **kwargs):
"""
Edit the selected message.
"""
return super(APIMessageView, self).put(*args, **kwargs)

View File

@@ -100,7 +100,6 @@ class Menu(object):
"""
Associate a link to a model, a view inside this menu
"""
try:
for source in sources:
self._map_links_to_source(
@@ -237,7 +236,6 @@ class Menu(object):
Allow unbinding links from sources, used to allow 3rd party apps to
change the link binding of core apps
"""
try:
for source in sources:
self._map_links_to_source(

View File

@@ -19,7 +19,6 @@ class OCRAPITestCase(BaseAPITestCase):
"""
Test the OCR app API endpoints
"""
def setUp(self):
super(OCRAPITestCase, self).setUp()
self.login_user()

View File

@@ -18,7 +18,6 @@ class BaseAPITestCase(UserMixin, APITestCase):
"""
API test case class that invalidates permissions and smart settings
"""
def setUp(self):
super(BaseAPITestCase, self).setUp()
Namespace.invalidate_cache_all()

View File

@@ -33,7 +33,6 @@ class APIStagingSourceListView(generics.ListAPIView):
"""
get: Returns a list of all the staging folders and the files they contain.
"""
serializer_class = StagingFolderSerializer
queryset = StagingFolderSource.objects.all()

View File

@@ -79,7 +79,6 @@ class DocumentUploadTestCase(GenericDocumentViewTestCase):
Test uploading of documents by granting the document create
permssion for the document type to the user
"""
self.login_user()
# Create an access control entry giving the role the document
@@ -226,7 +225,6 @@ class NewDocumentVersionViewTestCase(GenericDocumentViewTestCase):
- Link to upload version view should not resolve
- Upload version view should reject request
"""
self.login_admin_user()
NewVersionBlock.objects.block(self.document)

View File

@@ -22,7 +22,6 @@ def has_metadata_types(wizard):
"""
Skip the 2nd step if document type has no associated metadata
"""
cleaned_data = wizard.get_cleaned_data_for_step(STEP_DOCUMENT_TYPE) or {}
document_type = cleaned_data.get('document_type')

View File

@@ -2,7 +2,6 @@
This module should be called settings.py but is named conf.py to avoid a
class with the mayan/settings/* module
"""
from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _

View File

@@ -6,7 +6,6 @@ It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application