Make default transformation application a method of Document, and execute on both upload methods
This commit is contained in:
@@ -26,6 +26,7 @@ from documents.conf.settings import FILESYSTEM_FILESERVING_PATH
|
|||||||
from documents.conf.settings import FILESYSTEM_SLUGIFY_PATHS
|
from documents.conf.settings import FILESYSTEM_SLUGIFY_PATHS
|
||||||
from documents.conf.settings import FILESYSTEM_MAX_RENAME_COUNT
|
from documents.conf.settings import FILESYSTEM_MAX_RENAME_COUNT
|
||||||
from documents.conf.settings import AVAILABLE_TRANSFORMATIONS
|
from documents.conf.settings import AVAILABLE_TRANSFORMATIONS
|
||||||
|
from documents.conf.settings import DEFAULT_TRANSFORMATIONS
|
||||||
|
|
||||||
if FILESYSTEM_SLUGIFY_PATHS == False:
|
if FILESYSTEM_SLUGIFY_PATHS == False:
|
||||||
#Do not slugify path or filenames and extensions
|
#Do not slugify path or filenames and extensions
|
||||||
@@ -177,6 +178,21 @@ class Document(models.Model):
|
|||||||
metadata_groups[group] = Document.objects.filter(Q(id__in=document_id_list)) or []
|
metadata_groups[group] = Document.objects.filter(Q(id__in=document_id_list)) or []
|
||||||
return metadata_groups, errors
|
return metadata_groups, errors
|
||||||
|
|
||||||
|
|
||||||
|
def apply_default_transformations(self):
|
||||||
|
if DEFAULT_TRANSFORMATIONS:
|
||||||
|
for transformation in DEFAULT_TRANSFORMATIONS:
|
||||||
|
if 'name' in transformation:
|
||||||
|
for document_page in self.documentpage_set.all():
|
||||||
|
page_transformation = DocumentPageTransformation(
|
||||||
|
document_page=document_page,
|
||||||
|
order=0,
|
||||||
|
transformation=transformation['name'])
|
||||||
|
if 'arguments' in transformation:
|
||||||
|
page_transformation.arguments = transformation['arguments']
|
||||||
|
|
||||||
|
page_transformation.save()
|
||||||
|
|
||||||
|
|
||||||
def create_fs_links(self):
|
def create_fs_links(self):
|
||||||
if FILESYSTEM_FILESERVING_ENABLE:
|
if FILESYSTEM_FILESERVING_ENABLE:
|
||||||
|
|||||||
@@ -129,20 +129,7 @@ def upload_document_with_type(request, document_type_id, multiple=True):
|
|||||||
instance.update_checksum()
|
instance.update_checksum()
|
||||||
instance.update_mimetype()
|
instance.update_mimetype()
|
||||||
instance.update_page_count()
|
instance.update_page_count()
|
||||||
if DEFAULT_TRANSFORMATIONS:
|
instance.apply_default_transformations()
|
||||||
for transformation in DEFAULT_TRANSFORMATIONS:
|
|
||||||
if 'name' in transformation:
|
|
||||||
for document_page in instance.documentpage_set.all():
|
|
||||||
page_transformation = DocumentPageTransformation(
|
|
||||||
document_page=document_page,
|
|
||||||
order=0,
|
|
||||||
transformation=transformation['name'])
|
|
||||||
if 'arguments' in transformation:
|
|
||||||
page_transformation.arguments = transformation['arguments']
|
|
||||||
|
|
||||||
page_transformation.save()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if 'document_type_available_filenames' in local_form.cleaned_data:
|
if 'document_type_available_filenames' in local_form.cleaned_data:
|
||||||
if local_form.cleaned_data['document_type_available_filenames']:
|
if local_form.cleaned_data['document_type_available_filenames']:
|
||||||
@@ -177,6 +164,8 @@ def upload_document_with_type(request, document_type_id, multiple=True):
|
|||||||
document.update_checksum()
|
document.update_checksum()
|
||||||
document.update_mimetype()
|
document.update_mimetype()
|
||||||
document.update_page_count()
|
document.update_page_count()
|
||||||
|
document.apply_default_transformations()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
messages.error(request, e)
|
messages.error(request, e)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user