From 82099c2f1bcb3b0fe67c95ad57e7a440d7b34b7e Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 8 Jun 2018 17:03:46 -0400 Subject: [PATCH] Update the document print view to allow passing multiple document ids. Signed-off-by: Roberto Rosario --- mayan/apps/documents/apps.py | 7 ++-- mayan/apps/documents/links.py | 4 +++ .../templates/documents/document_print.html | 20 ++++++++--- mayan/apps/documents/urls.py | 4 +++ mayan/apps/documents/views/document_views.py | 33 ++++++++++++------- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/mayan/apps/documents/apps.py b/mayan/apps/documents/apps.py index 3416c1e1d4..b546b983a9 100644 --- a/mayan/apps/documents/apps.py +++ b/mayan/apps/documents/apps.py @@ -57,8 +57,8 @@ from .links import ( link_document_edit, link_document_list, link_document_list_deleted, link_document_list_recent, link_document_multiple_delete, link_document_multiple_trash, link_document_multiple_clear_transformations, - link_document_multiple_download, link_document_multiple_restore, - link_document_multiple_update_page_count, + link_document_multiple_download, link_document_multiple_print, + link_document_multiple_restore, link_document_multiple_update_page_count, link_document_page_navigation_first, link_document_page_navigation_last, link_document_page_navigation_next, link_document_page_navigation_previous, link_document_page_return, link_document_page_rotate_left, @@ -481,10 +481,11 @@ class DocumentsApp(MayanAppConfig): ) menu_multi_item.bind_links( links=( + link_document_multiple_print, link_document_multiple_clear_transformations, link_document_multiple_trash, link_document_multiple_download, link_document_multiple_update_page_count, - link_document_multiple_document_type_edit + link_document_multiple_document_type_edit, ), sources=(Document,) ) menu_multi_item.bind_links( diff --git a/mayan/apps/documents/links.py b/mayan/apps/documents/links.py index 9e168dd87e..441c48298a 100644 --- a/mayan/apps/documents/links.py +++ b/mayan/apps/documents/links.py @@ -110,6 +110,10 @@ link_document_print = Link( permissions=(permission_document_print,), text=_('Print'), view='documents:document_print', args='resolved_object.id' ) +link_document_multiple_print = Link( + tags='new_window', text=_('Print'), + view='documents:document_multiple_print', +) link_document_quick_download = Link( permissions=(permission_document_download,), text=_('Quick download'), view='documents:document_download', args='resolved_object.id' diff --git a/mayan/apps/documents/templates/documents/document_print.html b/mayan/apps/documents/templates/documents/document_print.html index 72bdd3b217..19b7fb2ab0 100644 --- a/mayan/apps/documents/templates/documents/document_print.html +++ b/mayan/apps/documents/templates/documents/document_print.html @@ -3,9 +3,19 @@ {% block title %}{{ title }}{% endblock title %} {% block content_plain %} - {% for page in pages %} - - {% endfor %} + {% if pages %} + {% for page in pages %} + + {% endfor %} + {% else %} + {% for document in documents %} + {% for page in document.pages.all %} + + {% endfor %} + {% endfor %} + {% endif %} {% endblock %} diff --git a/mayan/apps/documents/urls.py b/mayan/apps/documents/urls.py index 6ae245f96e..d1017f89f7 100644 --- a/mayan/apps/documents/urls.py +++ b/mayan/apps/documents/urls.py @@ -99,6 +99,10 @@ urlpatterns = [ r'^(?P\d+)/edit/$', DocumentEditView.as_view(), name='document_edit' ), + url( + r'^multiple/print/$', DocumentPrint.as_view(), + name='document_multiple_print' + ), url( r'^(?P\d+)/print/$', DocumentPrint.as_view(), name='document_print' diff --git a/mayan/apps/documents/views/document_views.py b/mayan/apps/documents/views/document_views.py index 60313eb94d..0da6622a49 100644 --- a/mayan/apps/documents/views/document_views.py +++ b/mayan/apps/documents/views/document_views.py @@ -713,28 +713,40 @@ class DocumentTransformationsCloneView(FormView): return instance +from common.mixins import MultipleObjectMixin -class DocumentPrint(FormView): +class DocumentPrint(MultipleObjectMixin, FormView): form_class = DocumentPrintForm + model = Document def dispatch(self, request, *args, **kwargs): - instance = self.get_object() - AccessControlList.objects.check_access( - permissions=permission_document_print, user=self.request.user, - obj=instance + self.queryset = AccessControlList.objects.filter_by_access( + permission=permission_document_print, user=self.request.user, + queryset=self.get_queryset() ) - instance.add_as_recent_document_for_user(self.request.user) + for document in self.queryset.all(): + document.add_as_recent_document_for_user(self.request.user) self.page_group = self.request.GET.get('page_group') self.page_range = self.request.GET.get('page_range') return super(DocumentPrint, self).dispatch(request, *args, **kwargs) def get(self, request, *args, **kwargs): + if self.queryset.count() > 1: + context = { + 'appearance_type': 'plain', + 'documents': self.queryset.all(), + 'width': setting_print_width.value, + 'height': setting_print_height.value, + } + + return self.render_to_response(context=context) + if not self.page_group and not self.page_range: return super(DocumentPrint, self).get(request, *args, **kwargs) else: - instance = self.get_object() + instance = self.queryset.first() if self.page_group == PAGE_RANGE_RANGE: if self.page_range: @@ -759,7 +771,7 @@ class DocumentPrint(FormView): return self.render_to_response(context=context) def get_extra_context(self): - instance = self.get_object() + instance = self.queryset.first() context = { 'form_action': reverse( @@ -774,11 +786,8 @@ class DocumentPrint(FormView): return context - def get_object(self): - return get_object_or_404(Document, pk=self.kwargs['pk']) - def get_template_names(self): - if self.page_group or self.page_range: + if self.page_group or self.page_range or self.queryset.count() > 1: return ('documents/document_print.html',) else: return (self.template_name,)