Browse Source

Korektury: oprava vytváření adresáře

remotes/origin/korekturovatko_emaily
Matěj Kocián 8 years ago
parent
commit
089ff4ff31
  1. 22
      korektury/models.py

22
korektury/models.py

@ -10,6 +10,7 @@ from django.core.exceptions import ObjectDoesNotExist
import subprocess import subprocess
from reversion import revisions as reversion from reversion import revisions as reversion
# PrilohaReseni method # PrilohaReseni method
def generate_filename(self, filename): def generate_filename(self, filename):
clean = filename.replace('/','-').replace('\0', '').replace(":","_") clean = filename.replace('/','-').replace('\0', '').replace(":","_")
@ -64,23 +65,18 @@ class KorekturovanePDF(models.Model):
except ObjectDoesNotExist: except ObjectDoesNotExist:
pass pass
super(KorekturovanePDF, self).save() 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] filename = os.path.split(self.pdf.file.name)[1].split(".")[0]
try: dirname = os.path.join(settings.MEDIA_ROOT, settings.KOREKTURY_IMG_DIR)
os.listdir(settings.KOREKTURY_IMG_DIR) if not os.path.exists(dirname):
except OSError: os.mkdir(dirname)
os.mkdir(settings.KOREKTURY_IMG_DIR)
while True: while True:
res = subprocess.call([ res = subprocess.call([
"convert", "convert",
"-density","180x180", "-density", "180x180",
"-geometry"," 1024x1448", "-geometry", " 1024x1448",
self.pdf.path+"[%d]"%self.stran, "%s[%d]" % (self.pdf.path, self.stran),
os.path.join(settings.BASE_DIR, "media", os.path.join(dirname, "%s-%d.png" % (filename, self.stran))
settings.KOREKTURY_IMG_DIR, ])
"%s-%d.png"%(filename,self.stran))])
if res==1: if res==1:
break break
self.stran +=1 self.stran +=1

Loading…
Cancel
Save