From 089ff4ff312dfc812bfcdce5a2f0193280d9ace8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Mon, 29 Aug 2016 14:59:10 +0200 Subject: [PATCH] =?UTF-8?q?Korektury:=20oprava=20vytv=C3=A1=C5=99en=C3=AD?= =?UTF-8?q?=20adres=C3=A1=C5=99e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/models.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/korektury/models.py b/korektury/models.py index 311d5e20..2ede1f7e 100644 --- a/korektury/models.py +++ b/korektury/models.py @@ -10,6 +10,7 @@ from django.core.exceptions import ObjectDoesNotExist import subprocess from reversion import revisions as reversion + # PrilohaReseni method def generate_filename(self, filename): clean = filename.replace('/','-').replace('\0', '').replace(":","_") @@ -64,23 +65,18 @@ class KorekturovanePDF(models.Model): except ObjectDoesNotExist: pass super(KorekturovanePDF, self).save() - print("\nSaving") - print(self.pdf.path) - print(self.pdf.url) filename = os.path.split(self.pdf.file.name)[1].split(".")[0] - try: - os.listdir(settings.KOREKTURY_IMG_DIR) - except OSError: - os.mkdir(settings.KOREKTURY_IMG_DIR) + dirname = os.path.join(settings.MEDIA_ROOT, settings.KOREKTURY_IMG_DIR) + if not os.path.exists(dirname): + os.mkdir(dirname) while True: res = subprocess.call([ - "convert", - "-density","180x180", - "-geometry"," 1024x1448", - self.pdf.path+"[%d]"%self.stran, - os.path.join(settings.BASE_DIR, "media", - settings.KOREKTURY_IMG_DIR, - "%s-%d.png"%(filename,self.stran))]) + "convert", + "-density", "180x180", + "-geometry", " 1024x1448", + "%s[%d]" % (self.pdf.path, self.stran), + os.path.join(dirname, "%s-%d.png" % (filename, self.stran)) + ]) if res==1: break self.stran +=1