coding style
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
import ghostscript
|
|
||||||
import locale
|
import locale
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from os.path import splitext, basename
|
||||||
|
|
||||||
|
import ghostscript
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.validators import ValidationError
|
from django.core.validators import ValidationError
|
||||||
@@ -10,7 +12,6 @@ from django.urls import reverse
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from os.path import splitext, basename
|
|
||||||
|
|
||||||
logger = logging.getLogger("blackboard")
|
logger = logging.getLogger("blackboard")
|
||||||
|
|
||||||
@@ -40,7 +41,6 @@ class JobPosting(models.Model):
|
|||||||
verbose_name="Veröffentlichung", default=timezone.now
|
verbose_name="Veröffentlichung", default=timezone.now
|
||||||
)
|
)
|
||||||
|
|
||||||
# Managers
|
|
||||||
all_job_postings = models.Manager()
|
all_job_postings = models.Manager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -53,32 +53,6 @@ class JobPosting(models.Model):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("blackboard")
|
return reverse("blackboard")
|
||||||
|
|
||||||
def pdf2jpeg(self, pdf_input_path, jpeg_output_path):
|
|
||||||
args = [
|
|
||||||
"pef2jpeg", # actual value doesn't matter
|
|
||||||
"-dNOPAUSE",
|
|
||||||
"-sDEVICE=jpeg",
|
|
||||||
"-dDEVICEWIDTHPOINTS=600",
|
|
||||||
"-dDEVICEHEIGHTPOINTS=800",
|
|
||||||
"-sOutputFile=" + jpeg_output_path,
|
|
||||||
pdf_input_path,
|
|
||||||
]
|
|
||||||
|
|
||||||
encoding = locale.getpreferredencoding()
|
|
||||||
args = [a.encode(encoding) for a in args]
|
|
||||||
|
|
||||||
# ghostscript.Ghostscript(*args)
|
|
||||||
with ghostscript.Ghostscript(*args) as g:
|
|
||||||
ghostscript.cleanup()
|
|
||||||
|
|
||||||
def clean(self):
|
|
||||||
count = 0
|
|
||||||
for i in self.pdf_location.name:
|
|
||||||
if i == ".":
|
|
||||||
count = count + 1
|
|
||||||
if count > 1: # if more than one dot in filename
|
|
||||||
raise ValidationError(_("Keine Dateien mit >1 Punkten im Namen erlaubt."))
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
@@ -101,3 +75,29 @@ class JobPosting(models.Model):
|
|||||||
self.pdf2jpeg(self.pdf_location.path, pdf_thumb_location_full)
|
self.pdf2jpeg(self.pdf_location.path, pdf_thumb_location_full)
|
||||||
logger.info("SavenThumbAs: " + self.pdf_thumb_location)
|
logger.info("SavenThumbAs: " + self.pdf_thumb_location)
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
count = 0
|
||||||
|
for i in self.pdf_location.name:
|
||||||
|
if i == ".":
|
||||||
|
count = count + 1
|
||||||
|
if count > 1: # if more than one dot in filename
|
||||||
|
raise ValidationError(_("Keine Dateien mit >1 Punkten im Namen erlaubt."))
|
||||||
|
|
||||||
|
def pdf2jpeg(self, pdf_input_path, jpeg_output_path):
|
||||||
|
args = [
|
||||||
|
"pef2jpeg", # actual value doesn't matter
|
||||||
|
"-dNOPAUSE",
|
||||||
|
"-sDEVICE=jpeg",
|
||||||
|
"-dDEVICEWIDTHPOINTS=600",
|
||||||
|
"-dDEVICEHEIGHTPOINTS=800",
|
||||||
|
"-sOutputFile=" + jpeg_output_path,
|
||||||
|
pdf_input_path,
|
||||||
|
]
|
||||||
|
|
||||||
|
encoding = locale.getpreferredencoding()
|
||||||
|
args = [a.encode(encoding) for a in args]
|
||||||
|
|
||||||
|
# ghostscript.Ghostscript(*args)
|
||||||
|
with ghostscript.Ghostscript(*args) as g:
|
||||||
|
ghostscript.cleanup()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user