|
|
|
|
@ -6,8 +6,7 @@ import tempfile |
|
|
|
|
from email.header import Header |
|
|
|
|
from time import time |
|
|
|
|
import simplejson as json |
|
|
|
|
|
|
|
|
|
import ghostscript |
|
|
|
|
import subprocess as s |
|
|
|
|
from django.contrib import messages |
|
|
|
|
from django.db import DatabaseError |
|
|
|
|
|
|
|
|
|
@ -404,27 +403,31 @@ class BaseViews(object): |
|
|
|
|
os.makedirs(tmp_media_dir) |
|
|
|
|
|
|
|
|
|
tmp_dir = tempfile.mkdtemp(dir=tmp_media_dir) |
|
|
|
|
os.chmod(tmp_dir, 755) |
|
|
|
|
# os.chmod(tmp_dir, 755) # TODO: check on ubuntu |
|
|
|
|
tmp_dirname = os.path.split(tmp_dir)[1] |
|
|
|
|
|
|
|
|
|
f = open(filename, 'wb') |
|
|
|
|
f.write(pdf) |
|
|
|
|
f.close() |
|
|
|
|
args = ["", |
|
|
|
|
|
|
|
|
|
args = ["gs", |
|
|
|
|
"-q", |
|
|
|
|
"-dNOPAUSE", "-dBATCH", "-dSAFER", |
|
|
|
|
"-sDEVICE=png16m", |
|
|
|
|
"-r150", |
|
|
|
|
"-sOutputFile=%s" % os.path.join(tmp_dir, "page-%03d.png"), |
|
|
|
|
"-f", filename |
|
|
|
|
] |
|
|
|
|
GS = ghostscript.Ghostscript(*args) |
|
|
|
|
|
|
|
|
|
p = s.Popen(args=args, stdout=s.PIPE, stderr=s.PIPE) |
|
|
|
|
# # ghostscript.Ghostscript(*args) # TODO: check on ubuntu |
|
|
|
|
p.wait() |
|
|
|
|
os.remove(filename) |
|
|
|
|
filename = '%s.pdf' % self.get_filename(*args, **kwargs) |
|
|
|
|
imgs = glob.glob(os.path.join(tmp_dir, '*.png')) |
|
|
|
|
imgs = [os.path.split(i)[1] for i in imgs] |
|
|
|
|
imgs = ['%stmp/%s/%s' % (MEDIA_URL, tmp_dirname, i) for i in imgs] |
|
|
|
|
email_form = self.EMAIL_FORM_CLASS() |
|
|
|
|
|
|
|
|
|
dictionary = { |
|
|
|
|
'obj': obj, |
|
|
|
|
'images': imgs, |
|
|
|
|
@ -444,7 +447,6 @@ class BaseViews(object): |
|
|
|
|
# else: |
|
|
|
|
# return HttpResponseServerError('Server error. Try later.') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def as_pdf(self, *args, **kwargs): |
|
|
|
|
"""Вывести документ в формате PDF в HttpResponse.""" |
|
|
|
|
try: |
|
|
|
|
@ -535,7 +537,7 @@ class BaseViews(object): |
|
|
|
|
initial = {} |
|
|
|
|
client = getattr(self.get_obj(kwargs['id']), 'client', None) |
|
|
|
|
if client: |
|
|
|
|
initial['to'] = client.contact_email # подставить в форму email клиента |
|
|
|
|
initial['to'] = client.contact_email # подставить в форму email клиента |
|
|
|
|
form = self.EMAIL_FORM_CLASS(initial=initial) |
|
|
|
|
|
|
|
|
|
dictionary = { |
|
|
|
|
|