Documents: Split monolith forms.py

Split the documents/forms.py into sub modules for each logical
unit: types, document, pages, versions.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-14 15:44:25 -04:00
parent 34443a715c
commit 315e70309b
8 changed files with 298 additions and 240 deletions
@@ -24,9 +24,49 @@ from ..settings import (
setting_zoom_percent_step
)
__all__ = (
'DocumentPageListView', 'DocumentPageNavigationFirst',
'DocumentPageNavigationLast', 'DocumentPageNavigationNext',
'DocumentPageNavigationPrevious', 'DocumentPageRotateLeftView',
'DocumentPageRotateRightView', 'DocumentPageView',
'DocumentPageViewResetView', 'DocumentPageZoomInView',
'DocumentPageZoomOutView',
)
logger = logging.getLogger(__name__)
class DocumentPageInteractiveTransformation(RedirectView):
def dispatch(self, request, *args, **kwargs):
object = self.get_object()
AccessControlList.objects.check_access(
permissions=permission_document_view, user=request.user,
obj=object
)
return super(DocumentPageInteractiveTransformation, self).dispatch(
request, *args, **kwargs
)
def get_object(self):
return get_object_or_404(DocumentPage, pk=self.kwargs['pk'])
def get_redirect_url(self, *args, **kwargs):
url = reverse(
'documents:document_page_view', args=(self.kwargs['pk'],)
)
query_dict = {
'rotation': int(
self.request.GET.get('rotation', DEFAULT_ROTATION)
), 'zoom': int(self.request.GET.get('zoom', DEFAULT_ZOOM_LEVEL))
}
self.transformation_function(query_dict)
return '{}?{}'.format(url, urlencode(query_dict))
class DocumentPageListView(SingleObjectListView):
def dispatch(self, request, *args, **kwargs):
AccessControlList.objects.check_access(
@@ -157,6 +197,20 @@ class DocumentPageNavigationPrevious(DocumentPageNavigationBase):
return document_page
class DocumentPageRotateLeftView(DocumentPageInteractiveTransformation):
def transformation_function(self, query_dict):
query_dict['rotation'] = (
query_dict['rotation'] - setting_rotation_step.value
) % 360
class DocumentPageRotateRightView(DocumentPageInteractiveTransformation):
def transformation_function(self, query_dict):
query_dict['rotation'] = (
query_dict['rotation'] + setting_rotation_step.value
) % 360
class DocumentPageView(SimpleView):
template_name = 'appearance/generic_form.html'
@@ -204,38 +258,6 @@ class DocumentPageViewResetView(RedirectView):
pattern_name = 'documents:document_page_view'
class DocumentPageInteractiveTransformation(RedirectView):
def dispatch(self, request, *args, **kwargs):
object = self.get_object()
AccessControlList.objects.check_access(
permissions=permission_document_view, user=request.user,
obj=object
)
return super(DocumentPageInteractiveTransformation, self).dispatch(
request, *args, **kwargs
)
def get_object(self):
return get_object_or_404(DocumentPage, pk=self.kwargs['pk'])
def get_redirect_url(self, *args, **kwargs):
url = reverse(
'documents:document_page_view', args=(self.kwargs['pk'],)
)
query_dict = {
'rotation': int(
self.request.GET.get('rotation', DEFAULT_ROTATION)
), 'zoom': int(self.request.GET.get('zoom', DEFAULT_ZOOM_LEVEL))
}
self.transformation_function(query_dict)
return '{}?{}'.format(url, urlencode(query_dict))
class DocumentPageZoomInView(DocumentPageInteractiveTransformation):
def transformation_function(self, query_dict):
zoom = query_dict['zoom'] + setting_zoom_percent_step.value
@@ -254,17 +276,3 @@ class DocumentPageZoomOutView(DocumentPageInteractiveTransformation):
zoom = setting_zoom_min_level.value
query_dict['zoom'] = zoom
class DocumentPageRotateLeftView(DocumentPageInteractiveTransformation):
def transformation_function(self, query_dict):
query_dict['rotation'] = (
query_dict['rotation'] - setting_rotation_step.value
) % 360
class DocumentPageRotateRightView(DocumentPageInteractiveTransformation):
def transformation_function(self, query_dict):
query_dict['rotation'] = (
query_dict['rotation'] + setting_rotation_step.value
) % 360
@@ -26,50 +26,16 @@ from ..permissions import (
from .document_views import DocumentListView
__all__ = (
'DocumentTypeCreateView', 'DocumentTypeDeleteView',
'DocumentTypeDocumentListView', 'DocumentTypeEditView',
'DocumentTypeListView', 'DocumentTypeFilenameCreateView',
'DocumentTypeFilenameDeleteView', 'DocumentTypeFilenameEditView',
'DocumentTypeFilenameListView'
)
logger = logging.getLogger(__name__)
class DocumentTypeDocumentListView(DocumentListView):
def get_document_type(self):
return get_object_or_404(DocumentType, pk=self.kwargs['pk'])
def get_document_queryset(self):
return self.get_document_type().documents.all()
def get_extra_context(self):
context = super(DocumentTypeDocumentListView, self).get_extra_context()
context.update(
{
'object': self.get_document_type(),
'title': _('Documents of type: %s') % self.get_document_type()
}
)
return context
class DocumentTypeListView(SingleObjectListView):
model = DocumentType
object_permission = permission_document_type_view
def get_extra_context(self):
return {
'hide_link': True,
'no_results_icon': icon_document_type_setup,
'no_results_main_link': link_document_type_create.resolve(
context=RequestContext(request=self.request)
),
'no_results_text': _(
'Document types are the most basic units of configuration. '
'Everything in the system will depend on them. '
'Define a document type for each type of physical '
'document you intend to upload. Example document types: '
'invoice, receipt, manual, prescription, balance sheet.'
),
'no_results_title': _('No document types available'),
'title': _('Document types'),
}
class DocumentTypeCreateView(SingleObjectCreateView):
fields = (
'label', 'trash_time_period', 'trash_time_unit', 'delete_time_period',
@@ -103,6 +69,24 @@ class DocumentTypeDeleteView(SingleObjectDeleteView):
}
class DocumentTypeDocumentListView(DocumentListView):
def get_document_type(self):
return get_object_or_404(DocumentType, pk=self.kwargs['pk'])
def get_document_queryset(self):
return self.get_document_type().documents.all()
def get_extra_context(self):
context = super(DocumentTypeDocumentListView, self).get_extra_context()
context.update(
{
'object': self.get_document_type(),
'title': _('Documents of type: %s') % self.get_document_type()
}
)
return context
class DocumentTypeEditView(SingleObjectEditView):
fields = (
'label', 'trash_time_period', 'trash_time_unit', 'delete_time_period',
@@ -124,6 +108,29 @@ class DocumentTypeEditView(SingleObjectEditView):
}
class DocumentTypeListView(SingleObjectListView):
model = DocumentType
object_permission = permission_document_type_view
def get_extra_context(self):
return {
'hide_link': True,
'no_results_icon': icon_document_type_setup,
'no_results_main_link': link_document_type_create.resolve(
context=RequestContext(request=self.request)
),
'no_results_text': _(
'Document types are the most basic units of configuration. '
'Everything in the system will depend on them. '
'Define a document type for each type of physical '
'document you intend to upload. Example document types: '
'invoice, receipt, manual, prescription, balance sheet.'
),
'no_results_title': _('No document types available'),
'title': _('Document types'),
}
class DocumentTypeFilenameCreateView(SingleObjectCreateView):
form_class = DocumentTypeFilenameForm_create
@@ -153,6 +160,31 @@ class DocumentTypeFilenameCreateView(SingleObjectCreateView):
return {'document_type': self.get_document_type()}
class DocumentTypeFilenameDeleteView(SingleObjectDeleteView):
model = DocumentTypeFilename
object_permission = permission_document_type_edit
def get_extra_context(self):
return {
'document_type': self.get_object().document_type,
'filename': self.get_object(),
'navigation_object_list': ('document_type', 'filename',),
'title': _(
'Delete the quick label: %(label)s, from document type '
'"%(document_type)s"?'
) % {
'document_type': self.get_object().document_type,
'label': self.get_object()
},
}
def get_post_action_redirect(self):
return reverse(
'documents:document_type_filename_list',
args=(self.get_object().document_type.pk,)
)
class DocumentTypeFilenameEditView(SingleObjectEditView):
fields = ('enabled', 'filename',)
model = DocumentTypeFilename
@@ -181,31 +213,6 @@ class DocumentTypeFilenameEditView(SingleObjectEditView):
)
class DocumentTypeFilenameDeleteView(SingleObjectDeleteView):
model = DocumentTypeFilename
object_permission = permission_document_type_edit
def get_extra_context(self):
return {
'document_type': self.get_object().document_type,
'filename': self.get_object(),
'navigation_object_list': ('document_type', 'filename',),
'title': _(
'Delete the quick label: %(label)s, from document type '
'"%(document_type)s"?'
) % {
'document_type': self.get_object().document_type,
'label': self.get_object()
},
}
def get_post_action_redirect(self):
return reverse(
'documents:document_type_filename_list',
args=(self.get_object().document_type.pk,)
)
class DocumentTypeFilenameListView(SingleObjectListView):
access_object_retrieve_method = 'get_document_type'
object_permission = permission_document_type_view
+2
View File
@@ -10,6 +10,8 @@ from mayan.apps.common.generics import ConfirmView
from ..permissions import permission_document_tools
from ..tasks import task_clear_image_cache, task_scan_duplicates_all
__all__ = ('ClearImageCacheView', 'ScanDuplicatedDocuments')
logger = logging.getLogger(__name__)