Add support for preserving the extension of document files when using the quick label feature. Added to the document properties edit view and the document upload view. Closes GitLab issue #360.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-09-05 04:06:13 -04:00
parent aac0852128
commit 435fa774f0
10 changed files with 145 additions and 29 deletions

View File

@@ -129,6 +129,10 @@
- Add custom AJAX spinner. - Add custom AJAX spinner.
- Complete refactor of the compress archive class support. Closes - Complete refactor of the compress archive class support. Closes
GitLab issue #7. GitLab issue #7.
- Add support for preserving the extension of document files when
using the quick label feature. Added to the document properties
edit view and the document upload view. Closes GitLab issue
#360.
3.0.3 (2018-08-17) 3.0.3 (2018-08-17)
================== ==================

View File

@@ -343,6 +343,12 @@ classes beyond the provide line chart.
- Remove the duplicated setting pdftotext_path from the OCR path. - Remove the duplicated setting pdftotext_path from the OCR path.
This is now handled by the document parsing app. This is now handled by the document parsing app.
- Implement partial refresh of the main menu. - Implement partial refresh of the main menu.
- Complete refactor of the compress archive class support. Closes
GitLab issue #7.
- Add support for preserving the extension of document files when
using the quick label feature. Added to the document properties
edit view and the document upload view. Closes GitLab issue
#360.
Removals Removals
@@ -426,5 +432,6 @@ Bugs fixed or issues closed
* `GitLab issue #7 <https://gitlab.com/mayan-edms/mayan-edms/issues/7>`_ Feature: other compressors than zip for compressed documents * `GitLab issue #7 <https://gitlab.com/mayan-edms/mayan-edms/issues/7>`_ Feature: other compressors than zip for compressed documents
* `GitLab issue #259 <https://gitlab.com/mayan-edms/mayan-edms/issues/259>`_ Thumbnails: why are they created on the fly (therefore: not cached) * `GitLab issue #259 <https://gitlab.com/mayan-edms/mayan-edms/issues/259>`_ Thumbnails: why are they created on the fly (therefore: not cached)
* `GitLab issue #360 <https://gitlab.com/mayan-edms/mayan-edms/issues/360>`_ Should quick rename (optionally) retain original file type extension?
.. _PyPI: https://pypi.python.org/pypi/mayan-edms/ .. _PyPI: https://pypi.python.org/pypi/mayan-edms/

View File

@@ -11,13 +11,13 @@ class DocumentAutoParsingTestCase(GenericDocumentTestCase):
@override_settings(DOCUMENT_PARSING_AUTO_PARSING=False) @override_settings(DOCUMENT_PARSING_AUTO_PARSING=False)
def test_disable_auto_parsing(self): def test_disable_auto_parsing(self):
self.create_document_type() self._create_document_type()
self.document = self.upload_document() self.document = self.upload_document()
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
self.document.latest_version.content().next() self.document.latest_version.content().next()
@override_settings(DOCUMENT_PARSING_AUTO_PARSING=True) @override_settings(DOCUMENT_PARSING_AUTO_PARSING=True)
def test_enabled_auto_parsing(self): def test_enabled_auto_parsing(self):
self.create_document_type() self._create_document_type()
self.document = self.upload_document() self.document = self.upload_document()
self.assertTrue('Mayan' in self.document.content().next()) self.assertTrue('Mayan' in self.document.content().next())

View File

@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
import logging import logging
import os
from django import forms from django import forms
from django.template.defaultfilters import filesizeformat from django.template.defaultfilters import filesizeformat
@@ -99,16 +100,42 @@ class DocumentForm(forms.ModelForm):
} }
) )
) )
self.fields['preserve_extension'] = forms.BooleanField(
label=_('Preserve extension'), required=False,
help_text=_(
'Takes the file extension and moves it to the end of the '
'filename allowing operating systems that rely on file '
'extensions to open document correctly.'
)
)
def clean(self): def clean(self):
if 'document_type_available_filenames' in self.cleaned_data: self.cleaned_data['label'] = self.get_final_label(
if self.cleaned_data['document_type_available_filenames']: # Fallback to the instance label if there is no label key or
self.cleaned_data['label'] = self.cleaned_data[ # there is a label key and is an empty string
'document_type_available_filenames' filename=self.cleaned_data.get('label') or self.instance.label
] )
return self.cleaned_data return self.cleaned_data
def get_final_label(self, filename):
if 'document_type_available_filenames' in self.cleaned_data:
if self.cleaned_data['document_type_available_filenames']:
if self.cleaned_data['preserve_extension']:
filename, extension = os.path.splitext(filename)
filename = '{}{}'.format(
self.cleaned_data[
'document_type_available_filenames'
].filename, extension
)
else:
filename = self.cleaned_data[
'document_type_available_filenames'
].filename
return filename
class DocumentPropertiesForm(DetailForm): class DocumentPropertiesForm(DetailForm):
""" """

View File

@@ -6,7 +6,10 @@ from django.conf import settings
from ..models import DocumentType from ..models import DocumentType
from .literals import TEST_DOCUMENT_TYPE_LABEL, TEST_SMALL_DOCUMENT_FILENAME from .literals import (
TEST_DOCUMENT_TYPE_LABEL, TEST_SMALL_DOCUMENT_FILENAME,
TEST_DOCUMENT_TYPE_QUICK_LABEL
)
__all__ = ('DocumentTestMixin',) __all__ = ('DocumentTestMixin',)
@@ -16,7 +19,7 @@ class DocumentTestMixin(object):
auto_upload_document = True auto_upload_document = True
test_document_filename = TEST_SMALL_DOCUMENT_FILENAME test_document_filename = TEST_SMALL_DOCUMENT_FILENAME
def create_document_type(self): def _create_document_type(self):
self.document_type = DocumentType.objects.create( self.document_type = DocumentType.objects.create(
label=TEST_DOCUMENT_TYPE_LABEL label=TEST_DOCUMENT_TYPE_LABEL
) )
@@ -36,7 +39,7 @@ class DocumentTestMixin(object):
) )
if self.auto_create_document_type: if self.auto_create_document_type:
self.create_document_type() self._create_document_type()
if self.auto_upload_document: if self.auto_upload_document:
self.document = self.upload_document() self.document = self.upload_document()
@@ -45,3 +48,10 @@ class DocumentTestMixin(object):
for document_type in DocumentType.objects.all(): for document_type in DocumentType.objects.all():
document_type.delete() document_type.delete()
super(DocumentTestMixin, self).tearDown() super(DocumentTestMixin, self).tearDown()
class DocumentTypeQuickLabelTestMixin(object):
def _create_quick_label(self):
self.document_type_filename = self.document_type.filenames.create(
filename=TEST_DOCUMENT_TYPE_QUICK_LABEL
)

View File

@@ -14,6 +14,7 @@ from .literals import (
TEST_DOCUMENT_TYPE_LABEL, TEST_DOCUMENT_TYPE_LABEL_EDITED, TEST_DOCUMENT_TYPE_LABEL, TEST_DOCUMENT_TYPE_LABEL_EDITED,
TEST_DOCUMENT_TYPE_QUICK_LABEL, TEST_DOCUMENT_TYPE_QUICK_LABEL_EDITED TEST_DOCUMENT_TYPE_QUICK_LABEL, TEST_DOCUMENT_TYPE_QUICK_LABEL_EDITED
) )
from .mixins import DocumentTypeQuickLabelTestMixin
class DocumentTypeViewsTestCase(GenericDocumentViewTestCase): class DocumentTypeViewsTestCase(GenericDocumentViewTestCase):
@@ -98,7 +99,7 @@ class DocumentTypeViewsTestCase(GenericDocumentViewTestCase):
) )
class DocumentTypeQuickLabelViewsTestCase(GenericDocumentViewTestCase): class DocumentTypeQuickLabelViewsTestCase(DocumentTypeQuickLabelTestMixin, GenericDocumentViewTestCase):
def setUp(self): def setUp(self):
super(DocumentTypeQuickLabelViewsTestCase, self).setUp() super(DocumentTypeQuickLabelViewsTestCase, self).setUp()
self.login_user() self.login_user()
@@ -130,11 +131,6 @@ class DocumentTypeQuickLabelViewsTestCase(GenericDocumentViewTestCase):
self.assertEqual(self.document_type.filenames.count(), 1) self.assertEqual(self.document_type.filenames.count(), 1)
def _create_quick_label(self):
self.document_type_filename = self.document_type.filenames.create(
filename=TEST_DOCUMENT_TYPE_QUICK_LABEL
)
def _request_quick_label_delete(self): def _request_quick_label_delete(self):
return self.post( return self.post(
viewname='documents:document_type_filename_delete', viewname='documents:document_type_filename_delete',

View File

@@ -2,6 +2,8 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import os
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.utils.encoding import force_text from django.utils.encoding import force_text
@@ -22,6 +24,7 @@ from .literals import (
TEST_DOCUMENT_TYPE_2_LABEL, TEST_SMALL_DOCUMENT_FILENAME, TEST_DOCUMENT_TYPE_2_LABEL, TEST_SMALL_DOCUMENT_FILENAME,
TEST_TRANSFORMATION_ARGUMENT, TEST_TRANSFORMATION_NAME, TEST_TRANSFORMATION_ARGUMENT, TEST_TRANSFORMATION_NAME,
) )
from .mixins import DocumentTypeQuickLabelTestMixin
class DocumentsViewsTestCase(GenericDocumentViewTestCase): class DocumentsViewsTestCase(GenericDocumentViewTestCase):
@@ -558,3 +561,74 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
) )
response = self._request_print_view() response = self._request_print_view()
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
class DocumentsQuickLabelViewsTestCase(DocumentTypeQuickLabelTestMixin, GenericDocumentViewTestCase):
def setUp(self):
super(DocumentsQuickLabelViewsTestCase, self).setUp()
self.login_user()
def _request_document_quick_label_edit_view(self, extra_data=None):
data = {
'document_type_available_filenames': self.document_type_filename.pk,
'label': '' # View needs at least an empty label for quick
# label to work. Cause is unknown.
}
data.update(extra_data or {})
return self.post(
viewname='documents:document_edit', args=(self.document.pk,),
data=data
)
def test_document_quick_label_no_permission(self):
self._create_quick_label()
response = self._request_document_quick_label_edit_view()
self.assertEqual(response.status_code, 403)
self.document.refresh_from_db()
def test_document_quick_label_with_access(self):
self._create_quick_label()
self.grant_access(
permission=permission_document_properties_edit, obj=self.document
)
response = self._request_document_quick_label_edit_view()
self.assertEqual(response.status_code, 302)
self.document.refresh_from_db()
self.assertEqual(
self.document.label, self.document_type_filename.filename
)
def test_document_quick_label_preserve_extension_with_access(self):
self._create_quick_label()
self.grant_access(
permission=permission_document_properties_edit, obj=self.document
)
filename, extension = os.path.splitext(self.document.label)
response = self._request_document_quick_label_edit_view(
extra_data={'preserve_extension': True}
)
self.assertEqual(response.status_code, 302)
self.document.refresh_from_db()
self.assertEqual(
self.document.label, '{}{}'.format(
self.document_type_filename.filename, extension
)
)
def test_document_quick_label_no_preserve_extension_with_access(self):
self._create_quick_label()
self.grant_access(
permission=permission_document_properties_edit, obj=self.document
)
filename, extension = os.path.splitext(self.document.label)
response = self._request_document_quick_label_edit_view(
extra_data={'preserve_extension': False}
)
self.assertEqual(response.status_code, 302)
self.document.refresh_from_db()
self.assertEqual(
self.document.label, self.document_type_filename.filename
)

View File

@@ -95,7 +95,9 @@ class DocumentVersionDownloadFormView(DocumentDownloadFormView):
DocumentVersionDownloadFormView, self DocumentVersionDownloadFormView, self
).get_extra_context() ).get_extra_context()
result['title'] = _('Download document version') result.update({
'title': _('Download document version'),
})
return result return result

View File

@@ -428,7 +428,7 @@ class MetadataTypeViewTestCase(DocumentTestMixin, MetadataTestsMixin, GenericVie
def test_metadata_type_relationship_view_no_permission(self): def test_metadata_type_relationship_view_no_permission(self):
self.login_user() self.login_user()
self._create_metadata_type() self._create_metadata_type()
self.create_document_type() self._create_document_type()
self.upload_document() self.upload_document()
response = self._request_metadata_type_relationship_edit_view() response = self._request_metadata_type_relationship_edit_view()
@@ -442,7 +442,7 @@ class MetadataTypeViewTestCase(DocumentTestMixin, MetadataTestsMixin, GenericVie
def test_metadata_type_relationship_view_with_document_type_access(self): def test_metadata_type_relationship_view_with_document_type_access(self):
self.login_user() self.login_user()
self._create_metadata_type() self._create_metadata_type()
self.create_document_type() self._create_document_type()
self.upload_document() self.upload_document()
self.grant_access( self.grant_access(
@@ -460,7 +460,7 @@ class MetadataTypeViewTestCase(DocumentTestMixin, MetadataTestsMixin, GenericVie
def test_metadata_type_relationship_view_with_metadata_type_access(self): def test_metadata_type_relationship_view_with_metadata_type_access(self):
self.login_user() self.login_user()
self._create_metadata_type() self._create_metadata_type()
self.create_document_type() self._create_document_type()
self.upload_document() self.upload_document()
self.grant_access( self.grant_access(
@@ -478,7 +478,7 @@ class MetadataTypeViewTestCase(DocumentTestMixin, MetadataTestsMixin, GenericVie
def test_metadata_type_relationship_view_with_metadata_type_and_document_type_access(self): def test_metadata_type_relationship_view_with_metadata_type_and_document_type_access(self):
self.login_user() self.login_user()
self._create_metadata_type() self._create_metadata_type()
self.create_document_type() self._create_document_type()
self.upload_document() self.upload_document()
self.grant_access( self.grant_access(

View File

@@ -243,12 +243,6 @@ class UploadInteractiveView(UploadBaseView):
file=uploaded_file.file file=uploaded_file.file
) )
label = None
if 'document_type_available_filenames' in forms['document_form'].cleaned_data:
if forms['document_form'].cleaned_data['document_type_available_filenames']:
label = forms['document_form'].cleaned_data['document_type_available_filenames'].filename
if not self.request.user.is_anonymous: if not self.request.user.is_anonymous:
user_id = self.request.user.pk user_id = self.request.user.pk
else: else:
@@ -265,7 +259,9 @@ class UploadInteractiveView(UploadBaseView):
description=forms['document_form'].cleaned_data.get('description'), description=forms['document_form'].cleaned_data.get('description'),
document_type_id=self.document_type.pk, document_type_id=self.document_type.pk,
expand=expand, expand=expand,
label=label, label=forms['document_form'].get_final_label(
filename=force_text(shared_uploaded_file)
),
language=forms['document_form'].cleaned_data.get('language'), language=forms['document_form'].cleaned_data.get('language'),
querystring=uri_to_iri( querystring=uri_to_iri(
'?{}&{}'.format( '?{}&{}'.format(