Fix error accidental delete of staging file on preview
This commit is contained in:
@@ -115,7 +115,7 @@ def in_image_cache(input_filepath, size, page=0, format='jpg', quality=QUALITY_D
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, format='jpg', extra_options='', mimetype=None, extension=None):
|
def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, format='jpg', extra_options='', mimetype=None, extension=None, cleanup=True):
|
||||||
unoconv_output = None
|
unoconv_output = None
|
||||||
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options)
|
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options)
|
||||||
if os.path.exists(output_filepath):
|
if os.path.exists(output_filepath):
|
||||||
@@ -140,7 +140,8 @@ def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, f
|
|||||||
errors = get_errors(error_string)
|
errors = get_errors(error_string)
|
||||||
raise ConvertError(status, errors)
|
raise ConvertError(status, errors)
|
||||||
finally:
|
finally:
|
||||||
cleanup(input_filepath)
|
if cleanup:
|
||||||
|
cleanup(input_filepath)
|
||||||
if unoconv_output:
|
if unoconv_output:
|
||||||
cleanup(unoconv_output)
|
cleanup(unoconv_output)
|
||||||
return output_filepath
|
return output_filepath
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ def document_download(request, document_id):
|
|||||||
def staging_file_preview(request, staging_file_id):
|
def staging_file_preview(request, staging_file_id):
|
||||||
try:
|
try:
|
||||||
filepath = StagingFile.get(staging_file_id).filepath
|
filepath = StagingFile.get(staging_file_id).filepath
|
||||||
output_file = convert(filepath, STAGING_FILES_PREVIEW_SIZE)
|
output_file = convert(filepath, STAGING_FILES_PREVIEW_SIZE, cleanup=False)
|
||||||
return serve_file(request, File(file=open(output_file, 'r')))
|
return serve_file(request, File(file=open(output_file, 'r')))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
return serve_file(request, File(file=open('%simages/1297211435_error.png' % settings.MEDIA_ROOT, 'r')))
|
return serve_file(request, File(file=open('%simages/1297211435_error.png' % settings.MEDIA_ROOT, 'r')))
|
||||||
|
|||||||
Reference in New Issue
Block a user