From 653a145914d4d1c3381b35abf68a607ab2c961cc Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 17 Jul 2015 13:04:51 -0400 Subject: [PATCH] Add tool view to perform OCR on all documents at once. --- mayan/apps/ocr/apps.py | 4 ++-- mayan/apps/ocr/links.py | 1 + mayan/apps/ocr/urls.py | 4 +++- mayan/apps/ocr/views.py | 16 ++++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mayan/apps/ocr/apps.py b/mayan/apps/ocr/apps.py index ca4495ff7e..5953e865ea 100644 --- a/mayan/apps/ocr/apps.py +++ b/mayan/apps/ocr/apps.py @@ -25,7 +25,7 @@ from rest_api.classes import APIEndPoint from .handlers import initialize_new_ocr_settings, post_version_upload_ocr from .links import ( - link_document_content, link_document_submit, + link_document_content, link_document_submit, link_document_submit_all, link_document_submit_multiple, link_document_type_ocr_settings, link_entry_delete, link_entry_delete_multiple, link_entry_list, link_entry_re_queue, link_entry_re_queue_multiple @@ -89,7 +89,7 @@ class OCRApp(MayanAppConfig): menu_object.bind_links(links=[link_entry_re_queue, link_entry_delete], sources=[DocumentVersionOCRError]) menu_object.bind_links(links=[link_document_type_ocr_settings], sources=[DocumentType]) menu_secondary.bind_links(links=[link_entry_list], sources=['ocr:entry_list', 'ocr:entry_delete_multiple', 'ocr:entry_re_queue_multiple', DocumentVersionOCRError]) - menu_tools.bind_links(links=[link_entry_list]) + menu_tools.bind_links(links=[link_document_submit_all, link_entry_list]) post_save.connect(initialize_new_ocr_settings, dispatch_uid='initialize_new_ocr_settings', sender=DocumentType) post_version_upload.connect(post_version_upload_ocr, dispatch_uid='post_version_upload_ocr', sender=DocumentVersion) diff --git a/mayan/apps/ocr/links.py b/mayan/apps/ocr/links.py index 41956835e9..bd5e845f84 100644 --- a/mayan/apps/ocr/links.py +++ b/mayan/apps/ocr/links.py @@ -11,6 +11,7 @@ from .permissions import ( link_document_content = Link(permissions=[permission_ocr_content_view], text=_('Content'), view='ocr:document_content', args='resolved_object.id') link_document_submit = Link(permissions=[permission_ocr_document], text=_('Submit for OCR'), view='ocr:document_submit', args='object.id') +link_document_submit_all = Link(icon='fa fa-font', permissions=[permission_ocr_document], text=_('OCR all documents'), view='ocr:document_submit_all') link_document_submit_multiple = Link(text=_('Submit for OCR'), view='ocr:document_submit_multiple') link_document_type_ocr_settings = Link(permissions=[permission_document_type_ocr_setup], text=_('Setup OCR'), view='ocr:document_type_ocr_settings', args='resolved_object.id') link_entry_delete = Link(permissions=[permission_ocr_document_delete], text=_('Delete'), view='ocr:entry_delete', args='object.id') diff --git a/mayan/apps/ocr/urls.py b/mayan/apps/ocr/urls.py index 5401f162b4..bc598f5ddb 100644 --- a/mayan/apps/ocr/urls.py +++ b/mayan/apps/ocr/urls.py @@ -4,13 +4,15 @@ from django.conf.urls import patterns, url from .api_views import DocumentVersionOCRView from .views import ( - DocumentManySubmitView, DocumentSubmitView, DocumentTypeSettingsEditView + DocumentSubmitView, DocumentAllSubmitView, DocumentManySubmitView, + DocumentTypeSettingsEditView ) urlpatterns = patterns( 'ocr.views', url(r'^(?P\d+)/content/$', 'document_content', name='document_content'), url(r'^document/(?P\d+)/submit/$', DocumentSubmitView.as_view(), name='document_submit'), + url(r'^document/all/submit/$', DocumentAllSubmitView.as_view(), name='document_submit_all'), url(r'^document/multiple/submit/$', DocumentManySubmitView.as_view(), name='document_submit_multiple'), url(r'^document_type/(?P\d+)/ocr/settings/$', DocumentTypeSettingsEditView.as_view(), name='document_type_ocr_settings'), diff --git a/mayan/apps/ocr/views.py b/mayan/apps/ocr/views.py index 10a7694f43..3da5fb4929 100644 --- a/mayan/apps/ocr/views.py +++ b/mayan/apps/ocr/views.py @@ -54,6 +54,22 @@ class DocumentSubmitView(ConfirmView): return HttpResponseRedirect(self.get_success_url()) +class DocumentAllSubmitView(ConfirmView): + extra_context = { + 'title': _('Submit all documents for OCR?') + } + + def post(self, request, *args, **kwargs): + count = 0 + for document in Document.objects.all(): + document.submit_for_ocr() + count += 1 + + messages.success(request, _('%d documents added to the OCR queue.') % count) + + return HttpResponseRedirect(self.get_success_url()) + + class DocumentManySubmitView(DocumentSubmitView): def get_context_data(self, **kwargs): context = super(DocumentManySubmitView, self).get_context_data(**kwargs)