Update single and multiple document OCR submit views to use MultipleObjectConfirmActionView instead of the deprecated MultipleInstanceActionMixin.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import override_settings
|
||||
|
||||
from documents.tests import GenericDocumentViewTestCase
|
||||
|
||||
from ..permissions import permission_ocr_content_view
|
||||
from ..permissions import permission_ocr_content_view, permission_ocr_document
|
||||
from ..utils import get_document_ocr_content
|
||||
|
||||
|
||||
@override_settings(OCR_AUTO_OCR=True)
|
||||
class OCRViewsTestCase(GenericDocumentViewTestCase):
|
||||
# PyOCR's leak descriptor in get_available_languages and image_to_string
|
||||
# Disable descriptor leak test until fixed in upstream
|
||||
@@ -18,39 +15,92 @@ class OCRViewsTestCase(GenericDocumentViewTestCase):
|
||||
super(OCRViewsTestCase, self).setUp()
|
||||
self.login_user()
|
||||
|
||||
def _document_content_view(self):
|
||||
def _request_document_content_view(self):
|
||||
return self.get(
|
||||
'ocr:document_content', args=(self.document.pk,)
|
||||
)
|
||||
|
||||
def test_document_content_view_no_permissions(self):
|
||||
response = self._document_content_view()
|
||||
self.document.submit_for_ocr()
|
||||
response = self._request_document_content_view()
|
||||
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_document_content_view_with_permission(self):
|
||||
self.grant_permission(permission=permission_ocr_content_view)
|
||||
def test_document_content_view_with_access(self):
|
||||
self.document.submit_for_ocr()
|
||||
self.grant_access(
|
||||
permission=permission_ocr_content_view, obj=self.document
|
||||
)
|
||||
|
||||
response = self._document_content_view()
|
||||
response = self._request_document_content_view()
|
||||
|
||||
self.assertContains(
|
||||
response, 'Mayan EDMS Documentation', status_code=200
|
||||
)
|
||||
|
||||
def test_document_ocr_download_view_no_permission(self):
|
||||
response = self.get(
|
||||
def _request_document_submit_view(self):
|
||||
return self.post(
|
||||
'ocr:document_submit', args=(self.document.pk,)
|
||||
)
|
||||
|
||||
def test_document_submit_view_no_permission(self):
|
||||
self._request_document_submit_view()
|
||||
self.assertEqual(
|
||||
''.join(self.document.latest_version.ocr_content()), ''
|
||||
)
|
||||
|
||||
def test_document_submit_view_with_access(self):
|
||||
self.grant_access(
|
||||
permission=permission_ocr_document, obj=self.document
|
||||
)
|
||||
self._request_document_submit_view()
|
||||
self.assertTrue(
|
||||
'Mayan EDMS Documentation' in ''.join(
|
||||
self.document.latest_version.ocr_content()
|
||||
)
|
||||
)
|
||||
|
||||
def _request_multiple_document_submit_view(self):
|
||||
return self.post(
|
||||
'ocr:document_submit_multiple',
|
||||
data={
|
||||
'id_list': self.document.pk,
|
||||
}
|
||||
)
|
||||
|
||||
def test_multiple_document_submit_view_no_permission(self):
|
||||
self._request_multiple_document_submit_view()
|
||||
self.assertEqual(
|
||||
''.join(self.document.latest_version.ocr_content()), ''
|
||||
)
|
||||
|
||||
def test_multiple_document_submit_view_with_access(self):
|
||||
self.grant_access(
|
||||
permission=permission_ocr_document, obj=self.document
|
||||
)
|
||||
self._request_multiple_document_submit_view()
|
||||
self.assertTrue(
|
||||
'Mayan EDMS Documentation' in ''.join(
|
||||
self.document.latest_version.ocr_content()
|
||||
)
|
||||
)
|
||||
|
||||
def _request_document_ocr_download_view(self):
|
||||
return self.get(
|
||||
'ocr:document_ocr_download', args=(self.document.pk,)
|
||||
)
|
||||
|
||||
def test_document_ocr_download_view_no_permission(self):
|
||||
self.document.submit_for_ocr()
|
||||
response = self._request_document_ocr_download_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
def test_document_download_view_with_permission(self):
|
||||
def test_document_ocr_download_view_with_permission(self):
|
||||
self.document.submit_for_ocr()
|
||||
self.expected_content_type = 'application/octet-stream; charset=utf-8'
|
||||
|
||||
self.grant_permission(permission=permission_ocr_content_view)
|
||||
response = self.get(
|
||||
'ocr:document_ocr_download', args=(self.document.pk,)
|
||||
)
|
||||
response = self._request_document_ocr_download_view()
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ from .api_views import (
|
||||
)
|
||||
from .views import (
|
||||
DocumentOCRContent, DocumentOCRDownloadView, DocumentOCRErrorsListView,
|
||||
DocumentSubmitView, DocumentSubmitManyView, DocumentTypeSettingsEditView,
|
||||
DocumentTypeSubmitView, EntryListView
|
||||
DocumentSubmitView, DocumentTypeSettingsEditView, DocumentTypeSubmitView,
|
||||
EntryListView
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
@@ -26,7 +26,7 @@ urlpatterns = [
|
||||
name='document_type_submit'
|
||||
),
|
||||
url(
|
||||
r'^document/multiple/submit/$', DocumentSubmitManyView.as_view(),
|
||||
r'^document/multiple/submit/$', DocumentSubmitView.as_view(),
|
||||
name='document_submit_multiple'
|
||||
),
|
||||
url(
|
||||
|
||||
@@ -4,14 +4,12 @@ from django.contrib import messages
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext
|
||||
|
||||
from acls.models import AccessControlList
|
||||
from common.generics import (
|
||||
ConfirmView, FormView, SingleObjectDetailView, SingleObjectDownloadView,
|
||||
SingleObjectEditView, SingleObjectListView
|
||||
FormView, MultipleObjectConfirmActionView, SingleObjectDetailView,
|
||||
SingleObjectDownloadView, SingleObjectEditView, SingleObjectListView
|
||||
)
|
||||
from common.mixins import MultipleInstanceActionMixin
|
||||
from documents.models import Document, DocumentType
|
||||
|
||||
from .forms import DocumentOCRContentForm, DocumentTypeSelectForm
|
||||
@@ -44,48 +42,28 @@ class DocumentOCRContent(SingleObjectDetailView):
|
||||
}
|
||||
|
||||
|
||||
class DocumentSubmitView(ConfirmView):
|
||||
def get_extra_context(self):
|
||||
return {
|
||||
'object': self.get_object(),
|
||||
'title': _('Submit "%s" to the OCR queue?') % self.get_object()
|
||||
}
|
||||
|
||||
def get_object(self):
|
||||
return Document.objects.get(pk=self.kwargs['pk'])
|
||||
|
||||
def object_action(self, instance):
|
||||
AccessControlList.objects.check_access(
|
||||
permissions=permission_ocr_document, user=self.request.user,
|
||||
obj=instance
|
||||
)
|
||||
|
||||
instance.submit_for_ocr()
|
||||
|
||||
def view_action(self):
|
||||
instance = self.get_object()
|
||||
|
||||
self.object_action(instance=instance)
|
||||
|
||||
messages.success(
|
||||
self.request,
|
||||
_('Document: %(document)s was added to the OCR queue.') % {
|
||||
'document': instance
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class DocumentSubmitManyView(MultipleInstanceActionMixin, DocumentSubmitView):
|
||||
class DocumentSubmitView(MultipleObjectConfirmActionView):
|
||||
model = Document
|
||||
object_permission = permission_ocr_document
|
||||
success_message = '%(count)d document submitted to the OCR queue.'
|
||||
success_message_plural = '%(count)d documents submitted to the OCR queue.'
|
||||
|
||||
def get_extra_context(self):
|
||||
# Override the base class method
|
||||
return {
|
||||
'title': _('Submit the selected documents to the OCR queue?')
|
||||
queryset = self.get_queryset()
|
||||
|
||||
result = {
|
||||
'title': ungettext(
|
||||
'Submit the selected document to the OCR queue?',
|
||||
'Submit the selected documents to the OCR queue?',
|
||||
queryset.count()
|
||||
)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
def object_action(self, form, instance):
|
||||
instance.submit_for_ocr()
|
||||
|
||||
|
||||
class DocumentTypeSubmitView(FormView):
|
||||
form_class = DocumentTypeSelectForm
|
||||
|
||||
Reference in New Issue
Block a user