Moved staging file preview creation logic from documents.views to staging.py
This commit is contained in:
@@ -7,6 +7,10 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.utils.translation import ugettext
|
||||
|
||||
from documents.conf.settings import STAGING_DIRECTORY
|
||||
from documents.conf.settings import DEFAULT_TRANSFORMATIONS
|
||||
from documents.conf.settings import STAGING_FILES_PREVIEW_SIZE
|
||||
from converter import TRANFORMATION_CHOICES
|
||||
from converter.api import convert#, in_image_cache, QUALITY_DEFAULT
|
||||
|
||||
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
|
||||
#TODO: Do benchmarks
|
||||
@@ -74,3 +78,19 @@ class StagingFile(object):
|
||||
pass
|
||||
else:
|
||||
raise OSError(ugettext(u'Unable to delete staging file: %s') % exc)
|
||||
|
||||
def preview(self):
|
||||
transformation_list = []
|
||||
errors = []
|
||||
for transformation in DEFAULT_TRANSFORMATIONS:
|
||||
try:
|
||||
if transformation['name'] in TRANFORMATION_CHOICES:
|
||||
output = TRANFORMATION_CHOICES[transformation['name']] % eval(transformation['arguments'])
|
||||
transformation_list.append(output)
|
||||
except Exception, e:
|
||||
errors.append(e)
|
||||
|
||||
tranformation_string = ' '.join(transformation_list)
|
||||
|
||||
output_file = convert(self.filepath, size=STAGING_FILES_PREVIEW_SIZE, extra_options=tranformation_string, cleanup_files=False)
|
||||
return output_file, errors
|
||||
|
||||
Reference in New Issue
Block a user