Move add_to_class functions to their own module
* The new module is called methods.py and found on each app. * Add keyword arguments to add_to_class instances. * Remove catch all exception handling for the check in and check out views. * Improve checkouts tests code reducing redundant code. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -39,7 +39,7 @@ class APIDocumentCabinetListView(generics.ListAPIView):
|
||||
obj=document
|
||||
)
|
||||
|
||||
queryset = document.document_cabinets().all()
|
||||
queryset = document.get_cabinets()
|
||||
return queryset
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from .links import (
|
||||
link_multiple_document_cabinet_remove
|
||||
)
|
||||
from .menus import menu_cabinets
|
||||
from .methods import method_get_document_cabinets
|
||||
from .permissions import (
|
||||
permission_cabinet_add_document, permission_cabinet_delete,
|
||||
permission_cabinet_edit, permission_cabinet_remove_document,
|
||||
@@ -52,8 +53,7 @@ class CabinetsApp(MayanAppConfig):
|
||||
# Add explicit order_by as DocumentCabinet ordering Meta option has no
|
||||
# effect.
|
||||
Document.add_to_class(
|
||||
'document_cabinets',
|
||||
lambda document: DocumentCabinet.objects.filter(documents=document).order_by('parent__label', 'label')
|
||||
name='document_cabinets', value=method_get_document_cabinets
|
||||
)
|
||||
|
||||
ModelPermission.register(
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.apps import apps
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
def method_get_document_cabinets(self):
|
||||
DocumentCabinet = apps.get_model(
|
||||
app_label='cabinets', model_name='DocumentCabinet'
|
||||
)
|
||||
|
||||
return DocumentCabinet.objects.filter(documents=self).order_by(
|
||||
'parent__label', 'label'
|
||||
)
|
||||
|
||||
|
||||
method_get_document_cabinets.help_text = _(
|
||||
'Return a list of cabinets containing the document'
|
||||
)
|
||||
method_get_document_cabinets.short_description = _('get_cabinets()')
|
||||
@@ -219,7 +219,7 @@ class DocumentCabinetListView(CabinetListView):
|
||||
}
|
||||
|
||||
def get_object_list(self):
|
||||
return self.document.document_cabinets().all()
|
||||
return self.document.document_cabinets()
|
||||
|
||||
|
||||
class DocumentAddToCabinetView(MultipleObjectFormActionView):
|
||||
|
||||
@@ -43,7 +43,7 @@ def widget_document_cabinets(document, user):
|
||||
)
|
||||
|
||||
cabinets = AccessControlList.objects.filter_by_access(
|
||||
permission_cabinet_view, user, queryset=document.document_cabinets().all()
|
||||
permission_cabinet_view, user, queryset=document.document_cabinets()
|
||||
)
|
||||
|
||||
return format_html_join(
|
||||
|
||||
Reference in New Issue
Block a user