diff --git a/apps/converter/api.py b/apps/converter/api.py index 41642769cc..b60640f973 100755 --- a/apps/converter/api.py +++ b/apps/converter/api.py @@ -47,9 +47,12 @@ def cache_cleanup(input_filepath, size, page=0, format='jpg'): def create_image_cache_filename(input_filepath, size, page=0, format='jpg'): - temp_filename, separator = os.path.splitext(os.path.basename(input_filepath)) - temp_path = os.path.join(TEMPORARY_DIRECTORY, temp_filename) - return '%s_%s%s%s' % (temp_path, size, os.extsep, format) + if input_filepath: + temp_filename, separator = os.path.splitext(os.path.basename(input_filepath)) + temp_path = os.path.join(TEMPORARY_DIRECTORY, temp_filename) + return '%s_%s%s%s' % (temp_path, size, os.extsep, format) + else: + return None def in_image_cache(input_filepath, size, page=0, format='jpg'): diff --git a/apps/documents/views.py b/apps/documents/views.py index 146bd8f1e5..211b280f8f 100755 --- a/apps/documents/views.py +++ b/apps/documents/views.py @@ -360,25 +360,24 @@ def document_edit_metadata(request, document_id): def get_document_image(request, document_id, size=PREVIEW_SIZE): document = get_object_or_404(Document, pk=document_id) - filepath = in_image_cache(document.checksum, size) + try: + filepath = in_image_cache(document.checksum, size) - if filepath: - return serve_file(request, File(file=open(filepath, 'r'))) - else: - try: - #Save to a temporary location - document.file.open() - desc = document.file.storage.open(document.file.path) - filepath = from_descriptor_to_tempfile(desc, document.checksum) - output_file = convert(filepath, size) - return serve_file(request, File(file=open(output_file, 'r'))) - except Exception, e: - if size == THUMBNAIL_SIZE: - return serve_file(request, File(file=open('%simages/picture_error.png' % settings.MEDIA_ROOT, 'r'))) - else: - return serve_file(request, File(file=open('%simages/1297211435_error.png' % settings.MEDIA_ROOT, 'r'))) - #messages.error(request, e) - #return HttpResponse(e) + if filepath: + return serve_file(request, File(file=open(filepath, 'r'))) + #Save to a temporary location + document.file.open() + desc = document.file.storage.open(document.file.path) + filepath = from_descriptor_to_tempfile(desc, document.checksum) + output_file = convert(filepath, size) + return serve_file(request, File(file=open(output_file, 'r'))) + except Exception, e: + if size == THUMBNAIL_SIZE: + return serve_file(request, File(file=open('%simages/picture_error.png' % settings.MEDIA_ROOT, 'r'))) + else: + return serve_file(request, File(file=open('%simages/1297211435_error.png' % settings.MEDIA_ROOT, 'r'))) + #messages.error(request, e) + #return HttpResponse(e) def document_thumbnail(request, document_id):