Merge remote-tracking branch 'origin/features/multi_version_document' into clients/bc
This commit is contained in:
@@ -80,6 +80,9 @@
|
||||
Deploy a Redis container.
|
||||
- Improve document version upload form.
|
||||
- Use dropzone for document version upload form.
|
||||
- Remove the DOCUMENTS_DISABLE_BASE_IMAGE_CACHE,
|
||||
DOCUMENTS_DISABLE_TRANSFORMED_IMAGE_CACHE, and
|
||||
DOCUMENTS_FIX_ORIENTATION settings.
|
||||
|
||||
3.2.8 (2019-10-01)
|
||||
==================
|
||||
|
||||
@@ -404,7 +404,8 @@ class APIDocumentTypeView(generics.RetrieveUpdateDestroyAPIView):
|
||||
'GET': (permission_document_type_view,),
|
||||
'PUT': (permission_document_type_edit,),
|
||||
'PATCH': (permission_document_type_edit,),
|
||||
'DELETE': (permission_document_type_delete,) }
|
||||
'DELETE': (permission_document_type_delete,)
|
||||
}
|
||||
permission_classes = (MayanPermission,)
|
||||
queryset = DocumentType.objects.all()
|
||||
|
||||
|
||||
@@ -9,9 +9,6 @@ def get_latest_version(document):
|
||||
|
||||
def operation_reset_document_pages(apps, schema_editor):
|
||||
Document = apps.get_model(app_label='documents', model_name='Document')
|
||||
DocumentPage = apps.get_model(
|
||||
app_label='documents', model_name='DocumentPage'
|
||||
)
|
||||
|
||||
# Define inside the function to use the migration's apps instance
|
||||
def pages_reset(document):
|
||||
@@ -40,9 +37,6 @@ def operation_reset_document_pages(apps, schema_editor):
|
||||
|
||||
def operation_reset_document_pages_reverse(apps, schema_editor):
|
||||
Document = apps.get_model(app_label='documents', model_name='Document')
|
||||
DocumentPage = apps.get_model(
|
||||
app_label='documents', model_name='DocumentPage'
|
||||
)
|
||||
|
||||
for document in Document.objects.using(schema_editor.connection.alias).all():
|
||||
for document_page in document.pages.all():
|
||||
|
||||
@@ -224,8 +224,8 @@ class Document(models.Model):
|
||||
self.latest_version.update_page_count()
|
||||
|
||||
for version_page in self.latest_version.pages.all():
|
||||
document_page = self.pages.create(
|
||||
content_object = version_page
|
||||
self.pages.create(
|
||||
content_object=version_page
|
||||
)
|
||||
|
||||
def restore(self):
|
||||
|
||||
@@ -23,7 +23,6 @@ from mayan.apps.converter.utils import get_converter_class
|
||||
|
||||
from ..managers import DocumentPageManager
|
||||
from ..settings import (
|
||||
setting_disable_base_image_cache, setting_disable_transformed_image_cache,
|
||||
setting_display_width, setting_display_height, setting_zoom_max_level,
|
||||
setting_zoom_min_level
|
||||
)
|
||||
|
||||
@@ -15,15 +15,13 @@ from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.converter.exceptions import InvalidOfficeFormat, PageCountError
|
||||
from mayan.apps.converter.layers import layer_saved_transformations
|
||||
from mayan.apps.converter.transformations import TransformationRotate
|
||||
from mayan.apps.converter.utils import get_converter_class
|
||||
from mayan.apps.mimetype.api import get_mimetype
|
||||
|
||||
from ..events import event_document_new_version, event_document_version_revert
|
||||
from ..literals import DOCUMENT_IMAGES_CACHE_NAME
|
||||
from ..managers import DocumentVersionManager
|
||||
from ..settings import setting_fix_orientation, setting_hash_block_size
|
||||
from ..settings import setting_hash_block_size
|
||||
from ..signals import post_document_created, post_version_upload
|
||||
from ..storages import storage_documentversion
|
||||
|
||||
@@ -152,15 +150,6 @@ class DocumentVersion(models.Model):
|
||||
"""
|
||||
return self.file.storage.exists(self.file.name)
|
||||
|
||||
def fix_orientation(self):
|
||||
for page in self.pages.all():
|
||||
degrees = page.detect_orientation()
|
||||
if degrees:
|
||||
layer_saved_transformations.add_to_object(
|
||||
obj=page, transformation=TransformationRotate,
|
||||
arguments='{{"degrees": {}}}'.format(360 - degrees)
|
||||
)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse(
|
||||
viewname='documents:document_version_view', kwargs={
|
||||
@@ -296,8 +285,6 @@ class DocumentVersion(models.Model):
|
||||
self.update_mimetype(save=False)
|
||||
self.save(append_pages=append_pages, _user=user)
|
||||
self.update_page_count(save=False)
|
||||
if setting_fix_orientation.value:
|
||||
self.fix_orientation()
|
||||
|
||||
logger.info(
|
||||
'New document version "%s" created for document: %s',
|
||||
@@ -330,7 +317,7 @@ class DocumentVersion(models.Model):
|
||||
if append_pages:
|
||||
for version_page in self.pages.all():
|
||||
self.document.pages.create(
|
||||
content_object = version_page
|
||||
content_object=version_page
|
||||
)
|
||||
else:
|
||||
self.document.pages_reset(update_page_count=False)
|
||||
|
||||
@@ -21,7 +21,6 @@ from mayan.apps.converter.utils import get_converter_class
|
||||
|
||||
from ..managers import DocumentVersionPageManager
|
||||
from ..settings import (
|
||||
setting_disable_base_image_cache, setting_disable_transformed_image_cache,
|
||||
setting_display_width, setting_display_height, setting_zoom_max_level,
|
||||
setting_zoom_min_level
|
||||
)
|
||||
@@ -67,16 +66,6 @@ class DocumentVersionPage(models.Model):
|
||||
self.cache_partition.delete()
|
||||
super(DocumentVersionPage, self).delete(*args, **kwargs)
|
||||
|
||||
#def detect_orientation(self):
|
||||
# with self.document_version.open() as file_object:
|
||||
# converter = get_converter_class()(
|
||||
# file_object=file_object,
|
||||
# mime_type=self.document_version.mimetype
|
||||
# )
|
||||
# return converter.detect_orientation(
|
||||
# page_number=self.page_number
|
||||
# )
|
||||
|
||||
@property
|
||||
def document(self):
|
||||
return self.document_version.document
|
||||
@@ -102,12 +91,12 @@ class DocumentVersionPage(models.Model):
|
||||
|
||||
return combined_cache_filename
|
||||
|
||||
#def get_absolute_url(self):
|
||||
# return reverse(
|
||||
# viewname='documents:document_version_page_view', kwargs={
|
||||
# 'pk': self.pk
|
||||
# }
|
||||
# )
|
||||
def get_absolute_url(self):
|
||||
return reverse(
|
||||
viewname='documents:document_version_page_view', kwargs={
|
||||
'pk': self.pk
|
||||
}
|
||||
)
|
||||
|
||||
def get_api_image_url(self, *args, **kwargs):
|
||||
"""
|
||||
@@ -241,10 +230,6 @@ class DocumentVersionPage(models.Model):
|
||||
)
|
||||
raise
|
||||
|
||||
#@property
|
||||
#def is_in_trash(self):
|
||||
# return self.document.is_in_trash
|
||||
|
||||
def get_label(self):
|
||||
return _(
|
||||
'Version page %(page_number)d out of %(total_pages)d of %(document)s'
|
||||
@@ -255,6 +240,10 @@ class DocumentVersionPage(models.Model):
|
||||
}
|
||||
get_label.short_description = _('Label')
|
||||
|
||||
@property
|
||||
def is_in_trash(self):
|
||||
return self.document_version.document.is_in_trash
|
||||
|
||||
def natural_key(self):
|
||||
return (self.page_number, self.document_version.natural_key())
|
||||
natural_key.dependencies = ['documents.DocumentVersion']
|
||||
|
||||
@@ -38,21 +38,6 @@ setting_documentimagecache_storage_arguments = namespace.add_setting(
|
||||
'Arguments to pass to the DOCUMENT_CACHE_STORAGE_BACKEND.'
|
||||
),
|
||||
)
|
||||
setting_disable_base_image_cache = namespace.add_setting(
|
||||
global_name='DOCUMENTS_DISABLE_BASE_IMAGE_CACHE', default=False,
|
||||
help_text=_(
|
||||
'Disables the first cache tier which stores high resolution, '
|
||||
'non transformed versions of documents\'s pages.'
|
||||
)
|
||||
)
|
||||
setting_disable_transformed_image_cache = namespace.add_setting(
|
||||
global_name='DOCUMENTS_DISABLE_TRANSFORMED_IMAGE_CACHE', default=False,
|
||||
help_text=_(
|
||||
'Disables the second cache tier which stores medium to low '
|
||||
'resolution, transformed (rotated, zoomed, etc) versions '
|
||||
'of documents\' pages.'
|
||||
)
|
||||
)
|
||||
setting_display_height = namespace.add_setting(
|
||||
global_name='DOCUMENTS_DISPLAY_HEIGHT', default=''
|
||||
)
|
||||
@@ -65,15 +50,6 @@ setting_favorite_count = namespace.add_setting(
|
||||
'Maximum number of favorite documents to remember per user.'
|
||||
)
|
||||
)
|
||||
setting_fix_orientation = namespace.add_setting(
|
||||
global_name='DOCUMENTS_FIX_ORIENTATION', default=False,
|
||||
help_text=_(
|
||||
'Detect the orientation of each of the document\'s pages '
|
||||
'and create a corresponding rotation transformation to '
|
||||
'display it rightside up. This is an experimental '
|
||||
'feature and it is disabled by default.'
|
||||
)
|
||||
)
|
||||
setting_hash_block_size = namespace.add_setting(
|
||||
global_name='DOCUMENTS_HASH_BLOCK_SIZE',
|
||||
default=DEFAULT_DOCUMENTS_HASH_BLOCK_SIZE, help_text=_(
|
||||
|
||||
@@ -21,7 +21,7 @@ from mayan.apps.converter.literals import DEFAULT_ROTATION, DEFAULT_ZOOM_LEVEL
|
||||
from ..forms import DocumentPageForm
|
||||
from ..icons import icon_document_pages
|
||||
from ..links import link_document_pages_reset
|
||||
from ..models import Document, DocumentPage, DocumentVersionPage
|
||||
from ..models import Document, DocumentPage
|
||||
from ..permissions import permission_document_edit, permission_document_view
|
||||
from ..settings import (
|
||||
setting_rotation_step, setting_zoom_percent_step, setting_zoom_max_level,
|
||||
|
||||
@@ -19,7 +19,6 @@ class Migration(migrations.Migration):
|
||||
name='document_page',
|
||||
field=models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
#name='document_version_page',
|
||||
related_name='ocr_content',
|
||||
to='documents.DocumentVersionPage',
|
||||
verbose_name='Document version page'
|
||||
@@ -38,5 +37,3 @@ class Migration(migrations.Migration):
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.utils.encoding import force_text, python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from mayan.apps.documents.models import (
|
||||
DocumentPage, DocumentType, DocumentVersion, DocumentVersionPage
|
||||
DocumentType, DocumentVersion, DocumentVersionPage
|
||||
)
|
||||
|
||||
from .managers import (
|
||||
|
||||
@@ -7,6 +7,13 @@ from .literals import TEST_SOURCE_LABEL, TEST_SOURCE_UNCOMPRESS_N
|
||||
|
||||
|
||||
class SourceTestMixin(object):
|
||||
auto_create_test_source = True
|
||||
|
||||
def setUp(self):
|
||||
super(SourceTestMixin, self).setUp()
|
||||
if self.auto_create_test_source:
|
||||
self._create_test_source()
|
||||
|
||||
def _create_test_source(self):
|
||||
self.test_source = WebFormSource.objects.create(
|
||||
enabled=True, label=TEST_SOURCE_LABEL,
|
||||
|
||||
@@ -39,7 +39,6 @@ class CompressedUploadsTestCase(SourceTestMixin, GenericDocumentTestCase):
|
||||
auto_upload_document = False
|
||||
|
||||
def test_upload_compressed_file(self):
|
||||
self._create_test_source()
|
||||
self.test_source.uncompress = SOURCE_UNCOMPRESS_CHOICE_Y
|
||||
self.test_source.save()
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ import shutil
|
||||
from mayan.apps.checkouts.models import NewVersionBlock
|
||||
from mayan.apps.common.tests.base import GenericViewTestCase
|
||||
from mayan.apps.documents.models import Document
|
||||
from mayan.apps.documents.permissions import permission_document_create
|
||||
from mayan.apps.documents.permissions import (
|
||||
permission_document_create, permission_document_new_version
|
||||
)
|
||||
from mayan.apps.documents.tests.base import GenericDocumentViewTestCase
|
||||
from mayan.apps.documents.tests.literals import (
|
||||
TEST_COMPRESSED_DOCUMENT_PATH, TEST_DOCUMENT_DESCRIPTION,
|
||||
@@ -28,6 +30,44 @@ from .literals import (
|
||||
from .mixins import SourceTestMixin, SourceViewTestMixin
|
||||
|
||||
|
||||
class DocumentViewTestMixin(object):
|
||||
def _request_test_document_append_pages_view(self):
|
||||
with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object:
|
||||
return self.post(
|
||||
viewname='sources:document_pages_append', kwargs={
|
||||
'document_pk': self.test_document.pk
|
||||
}, data={
|
||||
'source-file': file_object,
|
||||
'document-append_pages': True, # Needs to be explicit
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class DocumentViewTestCase(
|
||||
SourceTestMixin, DocumentViewTestMixin, GenericDocumentViewTestCase
|
||||
):
|
||||
def test_document_append_pages_view_no_permission(self):
|
||||
page_count = self.test_document.pages.count()
|
||||
|
||||
response = self._request_test_document_append_pages_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
self.assertEqual(self.test_document.pages.count(), page_count)
|
||||
|
||||
def test_document_append_pages_view_with_access(self):
|
||||
page_count = self.test_document.pages.count()
|
||||
|
||||
self.grant_access(
|
||||
obj=self.test_document,
|
||||
permission=permission_document_new_version
|
||||
)
|
||||
|
||||
response = self._request_test_document_append_pages_view()
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
self.assertTrue(self.test_document.pages.count() > page_count)
|
||||
|
||||
|
||||
class DocumentUploadWizardViewTestMixin(object):
|
||||
def _request_upload_wizard_view(self, document_path=TEST_SMALL_DOCUMENT_PATH):
|
||||
with open(document_path, mode='rb') as file_object:
|
||||
@@ -54,10 +94,6 @@ class DocumentUploadWizardViewTestCase(
|
||||
):
|
||||
auto_upload_document = False
|
||||
|
||||
def setUp(self):
|
||||
super(DocumentUploadWizardViewTestCase, self).setUp()
|
||||
self._create_test_source()
|
||||
|
||||
def test_upload_compressed_file(self):
|
||||
self.test_source.uncompress = SOURCE_UNCOMPRESS_CHOICE_Y
|
||||
self.test_source.save()
|
||||
@@ -188,7 +224,7 @@ class DocumentUploadIssueTestCase(GenericDocumentViewTestCase):
|
||||
self.assertEqual(document.description, TEST_DOCUMENT_DESCRIPTION)
|
||||
|
||||
|
||||
class NewDocumentVersionViewTestCase(GenericDocumentViewTestCase):
|
||||
class DocumentVersionUploadViewTestCase(GenericDocumentViewTestCase):
|
||||
auto_login_superuser = True
|
||||
auto_login_user = False
|
||||
create_test_case_superuser = True
|
||||
@@ -300,6 +336,8 @@ class StagingFolderViewTestCase(
|
||||
class SourcesViewTestCase(
|
||||
SourceTestMixin, SourceViewTestMixin, GenericViewTestCase
|
||||
):
|
||||
auto_create_test_source = False
|
||||
|
||||
def test_source_create_view_no_permission(self):
|
||||
response = self._request_setup_source_create_view()
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
Reference in New Issue
Block a user