diff --git a/HISTORY.rst b/HISTORY.rst index d6aecd57c3..f56486ba16 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -254,6 +254,8 @@ * Remove Internet Explorer specific markup. * Fix optional metadata remove when mixed with required metadata. +* Create intermedia file cache folder. Fixes preview errors + when the first document uploaded is an office file. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index b31fbf20e1..3cf18015fb 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -564,6 +564,8 @@ Other changes * Remove Internet Explorer specific markup. * Fix optional metadata remove when mixed with required metadata. +* Create intermedia file cache folder. Fixes preview errors + when the first document uploaded is an office file. Removals diff --git a/mayan/apps/documents/models/document_version_models.py b/mayan/apps/documents/models/document_version_models.py index bfc8952447..5008ddb0e4 100644 --- a/mayan/apps/documents/models/document_version_models.py +++ b/mayan/apps/documents/models/document_version_models.py @@ -7,6 +7,7 @@ import shutil import uuid from django.apps import apps +from django.core.files.base import ContentFile from django.db import models, transaction from django.template import Template, Context from django.urls import reverse @@ -177,6 +178,11 @@ class DocumentVersion(models.Model): converter = get_converter_class()(file_object=self.open()) pdf_file_object = converter.to_pdf() + # Since open "wb+" doesn't create files, check if the file + # exists, if not then create it + if not storage_documentimagecache.exists(cache_filename): + storage_documentimagecache.save(name=cache_filename, content=ContentFile(content='')) + with storage_documentimagecache.open(cache_filename, mode='wb+') as file_object: for chunk in pdf_file_object: file_object.write(chunk)