Create the document image cache file it is doesn't exist.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-04-05 19:15:27 -04:00
parent a0b7561ed7
commit 1d55e67b00

View File

@@ -7,6 +7,7 @@ import uuid
from django.conf import settings
from django.core.files import File
from django.core.files.base import ContentFile
from django.db import models, transaction
from django.template import Template, Context
from django.urls import reverse
@@ -858,6 +859,11 @@ class DocumentPage(models.Model):
page_image = converter.get_page()
# Since open "wb+" doesn't create files, check if the file
# exists, if not then create it
if not documentimagecache_storage.exists(cache_filename):
documentimagecache_storage.save(name=cache_filename, content=ContentFile(content=''))
with documentimagecache_storage.open(cache_filename, 'wb+') as file_object:
file_object.write(page_image.getvalue())
except Exception as exception: