Create intermedia file cache folder

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-05-12 02:24:45 -04:00
parent 17030472f1
commit 1acc352801
3 changed files with 10 additions and 0 deletions

View File

@@ -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)