Add view to queue document for OCR by document type.
This commit is contained in:
@@ -335,8 +335,12 @@ Other changes
|
||||
* Normalization of 'title' and 'name' fields to 'label'.
|
||||
* Improved API, now at version 1.
|
||||
* Invert page title/project name order in browser title.
|
||||
* Use Django's class based views pagination
|
||||
* Use Django's class based views pagination.
|
||||
* Reduction of text strings.
|
||||
* OCR all documents.
|
||||
* Add tool to OCR all documents of a type.
|
||||
* Fix rendering of text files with Unicode characters.
|
||||
* Capture body of emails as a text document.
|
||||
|
||||
Removals
|
||||
--------
|
||||
@@ -347,7 +351,6 @@ Removals
|
||||
* Removal of the DOCUMENT_RESTRICTIONS_OVERRIDE permission
|
||||
* Removed the page_label field
|
||||
|
||||
|
||||
Upgrading from a previous version
|
||||
---------------------------------
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic import FormView, DetailView, TemplateView
|
||||
from django.views.generic import (
|
||||
FormView as DjangoFormView, DetailView, TemplateView
|
||||
)
|
||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
from django.views.generic.list import ListView
|
||||
|
||||
@@ -17,7 +19,7 @@ from .mixins import * # NOQA
|
||||
from .settings import setting_paginate_by
|
||||
|
||||
__all__ = (
|
||||
'AssignRemoveView', 'ConfirmView', 'MultiFormView',
|
||||
'AssignRemoveView', 'ConfirmView', 'FormView', 'MultiFormView',
|
||||
'SingleObjectCreateView', 'SingleObjectDeleteView',
|
||||
'SingleObjectDetailView', 'SingleObjectEditView', 'SingleObjectListView',
|
||||
'SimpleView',
|
||||
@@ -174,7 +176,11 @@ class ConfirmView(ObjectListPermissionFilterMixin, ViewPermissionCheckMixin, Ext
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
|
||||
class MultiFormView(FormView):
|
||||
class FormView(ViewPermissionCheckMixin, ExtraContextMixin, RedirectionMixin, DjangoFormView):
|
||||
template_name = 'appearance/generic_form.html'
|
||||
|
||||
|
||||
class MultiFormView(DjangoFormView):
|
||||
prefixes = {}
|
||||
|
||||
prefix = None
|
||||
|
||||
@@ -27,8 +27,8 @@ from .handlers import initialize_new_ocr_settings, post_version_upload_ocr
|
||||
from .links import (
|
||||
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
|
||||
link_document_type_submit, link_entry_delete, link_entry_delete_multiple,
|
||||
link_entry_list, link_entry_re_queue, link_entry_re_queue_multiple
|
||||
)
|
||||
from .models import DocumentVersionOCRError
|
||||
from .permissions import permission_ocr_document, permission_ocr_content_view
|
||||
@@ -128,7 +128,10 @@ class OCRApp(MayanAppConfig):
|
||||
)
|
||||
)
|
||||
menu_tools.bind_links(
|
||||
links=(link_document_submit_all, link_entry_list)
|
||||
links=(
|
||||
link_document_submit_all, link_document_type_submit,
|
||||
link_entry_list
|
||||
)
|
||||
)
|
||||
|
||||
post_save.connect(
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import ugettext_lazy as _, ugettext
|
||||
|
||||
from common.widgets import TextAreaDiv
|
||||
from documents.models import DocumentType
|
||||
|
||||
from .models import DocumentPageContent
|
||||
|
||||
@@ -52,3 +53,9 @@ class DocumentContentForm(forms.Form):
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class DocumentTypeSelectForm(forms.Form):
|
||||
document_type = forms.ModelChoiceField(
|
||||
queryset=DocumentType.objects.all(), label=('Document type')
|
||||
)
|
||||
|
||||
@@ -28,6 +28,10 @@ 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_document_type_submit = Link(
|
||||
icon='fa fa-font', permissions=(permission_ocr_document,),
|
||||
text=_('OCR documents per type'), view='ocr:document_type_submit'
|
||||
)
|
||||
link_entry_delete = Link(
|
||||
permissions=(permission_ocr_document_delete,), text=_('Delete'),
|
||||
view='ocr:entry_delete', args='object.id'
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.conf.urls import patterns, url
|
||||
from .api_views import DocumentVersionOCRView
|
||||
from .views import (
|
||||
DocumentAllSubmitView, DocumentSubmitView, DocumentSubmitManyView,
|
||||
DocumentTypeSettingsEditView, EntryListView
|
||||
DocumentTypeSettingsEditView, DocumentTypeSubmitView, EntryListView
|
||||
)
|
||||
|
||||
urlpatterns = patterns(
|
||||
@@ -22,6 +22,10 @@ urlpatterns = patterns(
|
||||
r'^document/all/submit/$', DocumentAllSubmitView.as_view(),
|
||||
name='document_submit_all'
|
||||
),
|
||||
url(
|
||||
r'^document/type/submit/$', DocumentTypeSubmitView.as_view(),
|
||||
name='document_type_submit'
|
||||
),
|
||||
url(
|
||||
r'^document/multiple/submit/$', DocumentSubmitManyView.as_view(),
|
||||
name='document_submit_multiple'
|
||||
|
||||
@@ -11,13 +11,13 @@ from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
from acls.models import AccessControlList
|
||||
from common.generics import (
|
||||
ConfirmView, SingleObjectEditView, SingleObjectListView
|
||||
ConfirmView, FormView, SingleObjectEditView, SingleObjectListView
|
||||
)
|
||||
from common.mixins import MultipleInstanceActionMixin
|
||||
from documents.models import Document, DocumentType, DocumentVersion
|
||||
from permissions import Permission
|
||||
|
||||
from .forms import DocumentContentForm
|
||||
from .forms import DocumentContentForm, DocumentTypeSelectForm
|
||||
from .models import DocumentVersionOCRError
|
||||
from .permissions import (
|
||||
permission_ocr_content_view, permission_ocr_document,
|
||||
@@ -89,6 +89,35 @@ class DocumentSubmitManyView(MultipleInstanceActionMixin, DocumentSubmitView):
|
||||
}
|
||||
|
||||
|
||||
class DocumentTypeSubmitView(FormView):
|
||||
form_class = DocumentTypeSelectForm
|
||||
extra_context = {
|
||||
'title': _('Submit all documents of a type for OCR')
|
||||
}
|
||||
|
||||
def get_post_action_redirect(self):
|
||||
return reverse('common:tools_list')
|
||||
|
||||
def form_valid(self, form):
|
||||
count = 0
|
||||
print form.cleaned_data
|
||||
for document in form.cleaned_data['document_type'].documents.all():
|
||||
document.submit_for_ocr()
|
||||
count += 1
|
||||
|
||||
messages.success(
|
||||
self.request, _(
|
||||
'%(count)d documents of type "%(document_type)s" added to the '
|
||||
'OCR queue.'
|
||||
) % {
|
||||
'count': count,
|
||||
'document_type': form.cleaned_data['document_type']
|
||||
}
|
||||
)
|
||||
|
||||
return HttpResponseRedirect(self.get_success_url())
|
||||
|
||||
|
||||
class DocumentTypeSettingsEditView(SingleObjectEditView):
|
||||
fields = ('auto_ocr',)
|
||||
view_permission = permission_document_type_ocr_setup
|
||||
|
||||
Reference in New Issue
Block a user