Browse Source

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

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

24
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

Loading…
Cancel
Save