diff --git a/HISTORY.rst b/HISTORY.rst index 48dd18c87a..6832fc7a71 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -125,6 +125,7 @@ permissions is now required to view the parsing error list. - The document type parsing setup permission can now be granted for individual document types. +- Add link to view a specific page's OCR content. 3.0.3 (2018-08-17) ================== diff --git a/mayan/apps/ocr/apps.py b/mayan/apps/ocr/apps.py index 083d59c304..089a07deab 100644 --- a/mayan/apps/ocr/apps.py +++ b/mayan/apps/ocr/apps.py @@ -27,10 +27,11 @@ from .handlers import ( handler_initialize_new_ocr_settings, handler_ocr_document_version, ) from .links import ( - link_document_content, link_document_ocr_download, - link_document_ocr_errors_list, link_document_submit, - link_document_submit_multiple, link_document_type_ocr_settings, - link_document_type_submit, link_entry_list + link_document_page_ocr_content, link_document_ocr_content, + link_document_ocr_download, link_document_ocr_errors_list, + link_document_submit, link_document_submit_multiple, + link_document_type_ocr_settings, link_document_type_submit, + link_entry_list ) from .permissions import ( permission_document_type_ocr_setup, permission_ocr_document, @@ -74,6 +75,9 @@ class OCRApp(MayanAppConfig): Document = apps.get_model( app_label='documents', model_name='Document' ) + DocumentPage = apps.get_model( + app_label='documents', model_name='DocumentPage' + ) DocumentType = apps.get_model( app_label='documents', model_name='DocumentType' ) @@ -141,7 +145,10 @@ class OCRApp(MayanAppConfig): ) menu_facet.bind_links( - links=(link_document_content,), sources=(Document,) + links=(link_document_ocr_content,), sources=(Document,) + ) + menu_facet.bind_links( + links=(link_document_page_ocr_content,), sources=(DocumentPage,) ) menu_multi_item.bind_links( links=(link_document_submit_multiple,), sources=(Document,) @@ -149,12 +156,15 @@ class OCRApp(MayanAppConfig): menu_object.bind_links( links=(link_document_submit,), sources=(Document,) ) + menu_object.bind_links( + links=(link_document_page_ocr_content,), sources=(DocumentPage,) + ) menu_object.bind_links( links=(link_document_type_ocr_settings,), sources=(DocumentType,) ) menu_secondary.bind_links( links=( - link_document_content, link_document_ocr_errors_list, + link_document_ocr_content, link_document_ocr_errors_list, link_document_ocr_download ), sources=( diff --git a/mayan/apps/ocr/forms.py b/mayan/apps/ocr/forms.py index 723912e0b2..76be2c3078 100644 --- a/mayan/apps/ocr/forms.py +++ b/mayan/apps/ocr/forms.py @@ -12,6 +12,33 @@ from documents.models import DocumentType from .models import DocumentPageOCRContent +class DocumentPageOCRContentForm(forms.Form): + def __init__(self, *args, **kwargs): + page = kwargs.pop('instance', None) + super(DocumentPageOCRContentForm, self).__init__(*args, **kwargs) + content = '' + self.fields['contents'].initial = '' + + try: + page_content = page.ocr_content.content + except DocumentPageOCRContent.DoesNotExist: + pass + else: + content = conditional_escape(force_text(page_content)) + + self.fields['contents'].initial = mark_safe(content) + + contents = forms.CharField( + label=_('Contents'), + widget=TextAreaDiv( + attrs={ + 'class': 'text_area_div full-height', + 'data-height-difference': 360 + } + ) + ) + + class DocumentOCRContentForm(forms.Form): """ Form that concatenates all of a document pages' text content into a diff --git a/mayan/apps/ocr/links.py b/mayan/apps/ocr/links.py index 6aa928b700..3e86783749 100644 --- a/mayan/apps/ocr/links.py +++ b/mayan/apps/ocr/links.py @@ -14,10 +14,15 @@ from .permissions import ( permission_document_type_ocr_setup ) -link_document_content = Link( +link_document_page_ocr_content = Link( args='resolved_object.id', icon_class=icon_document_content, permissions=(permission_ocr_content_view,), text=_('OCR'), - view='ocr:document_content', + view='ocr:document_page_ocr_content', +) +link_document_ocr_content = Link( + args='resolved_object.id', icon_class=icon_document_content, + permissions=(permission_ocr_content_view,), text=_('OCR'), + view='ocr:document_ocr_content', ) link_document_submit = Link( args='resolved_object.id', permissions=(permission_ocr_document,), diff --git a/mayan/apps/ocr/urls.py b/mayan/apps/ocr/urls.py index 383b0bf187..d23837718d 100644 --- a/mayan/apps/ocr/urls.py +++ b/mayan/apps/ocr/urls.py @@ -8,14 +8,18 @@ from .api_views import ( ) from .views import ( DocumentOCRContent, DocumentOCRDownloadView, DocumentOCRErrorsListView, - DocumentSubmitView, DocumentTypeSettingsEditView, DocumentTypeSubmitView, - EntryListView + DocumentPageOCRContent, DocumentSubmitView, DocumentTypeSettingsEditView, + DocumentTypeSubmitView, EntryListView ) urlpatterns = [ url( - r'^(?P\d+)/content/$', DocumentOCRContent.as_view(), - name='document_content' + r'^document/page/(?P\d+)/content/$', + DocumentPageOCRContent.as_view(), name='document_page_ocr_content' + ), + url( + r'^document/(?P\d+)/content/$', DocumentOCRContent.as_view(), + name='document_ocr_content' ), url( r'^document/(?P\d+)/submit/$', DocumentSubmitView.as_view(), diff --git a/mayan/apps/ocr/views.py b/mayan/apps/ocr/views.py index fc9e070b0f..10ad7cc5f4 100644 --- a/mayan/apps/ocr/views.py +++ b/mayan/apps/ocr/views.py @@ -10,9 +10,12 @@ from common.generics import ( FormView, MultipleObjectConfirmActionView, SingleObjectDetailView, SingleObjectDownloadView, SingleObjectEditView, SingleObjectListView ) -from documents.models import Document, DocumentType +from documents.models import Document, DocumentPage, DocumentType -from .forms import DocumentOCRContentForm, DocumentTypeSelectForm +from .forms import ( + DocumentPageOCRContentForm, DocumentOCRContentForm, + DocumentTypeSelectForm +) from .models import DocumentVersionOCRError from .permissions import ( permission_ocr_content_view, permission_ocr_document, @@ -30,7 +33,7 @@ class DocumentOCRContent(SingleObjectDetailView): result = super(DocumentOCRContent, self).dispatch( request, *args, **kwargs ) - self.get_object().add_as_recent_document_for_user(request.user) + self.get_object().add_as_recent_document_for_user(user=request.user) return result def get_extra_context(self): @@ -42,6 +45,28 @@ class DocumentOCRContent(SingleObjectDetailView): } +class DocumentPageOCRContent(SingleObjectDetailView): + form_class = DocumentPageOCRContentForm + model = DocumentPage + object_permission = permission_ocr_content_view + + def dispatch(self, request, *args, **kwargs): + result = super(DocumentPageOCRContent, self).dispatch( + request, *args, **kwargs + ) + self.get_object().document.add_as_recent_document_for_user( + user=request.user + ) + return result + + def get_extra_context(self): + return { + 'hide_labels': True, + 'object': self.get_object(), + 'title': _('OCR result for document page: %s') % self.get_object(), + } + + class DocumentSubmitView(MultipleObjectConfirmActionView): model = Document object_permission = permission_ocr_document