#155: Remove header/footer in frameless PDF.
This commit is contained in:
parent
dd10a59533
commit
4e8e9b5407
@ -33,7 +33,7 @@ from django.db import transaction
|
||||
|
||||
from reportlab.lib import colors
|
||||
from reportlab.lib.units import cm
|
||||
from reportlab.platypus import PageBreak, Paragraph, Spacer, Table, TableStyle
|
||||
from reportlab.platypus import SimpleDocTemplate, PageBreak, Paragraph, Spacer, Table, TableStyle
|
||||
|
||||
from config.models import config
|
||||
from settings import SITE_ROOT
|
||||
@ -796,6 +796,12 @@ class ApplicationPollPDF(PDFView):
|
||||
filename = u'%s%s_%s' % (_("Application"), str(self.poll.application.number), _("Poll"))
|
||||
return filename
|
||||
|
||||
def get_template(self, buffer):
|
||||
return SimpleDocTemplate(buffer, topMargin=-6, bottomMargin=-6, leftMargin=0, rightMargin=0, showBoundary=False)
|
||||
|
||||
def build_document(self, pdf_document, story):
|
||||
pdf_document.build(story)
|
||||
|
||||
def append_to_pdf(self, story):
|
||||
imgpath = os.path.join(SITE_ROOT, 'static/images/circle.png')
|
||||
circle = "<img src='%s' width='15' height='15'/> " % imgpath
|
||||
|
@ -20,7 +20,7 @@ from django.utils.translation import ugettext as _
|
||||
|
||||
from reportlab.lib import colors
|
||||
from reportlab.lib.units import cm
|
||||
from reportlab.platypus import PageBreak, Paragraph, Spacer, Table, TableStyle
|
||||
from reportlab.platypus import SimpleDocTemplate, PageBreak, Paragraph, Spacer, Table, TableStyle
|
||||
|
||||
from config.models import config
|
||||
|
||||
@ -294,9 +294,17 @@ class AssignmentPollDelete(DeleteView):
|
||||
|
||||
class AssignmentPDF(PDFView):
|
||||
permission_required = 'assignment.can_manage_assignment'
|
||||
filename = u'filename=%s.pdf;' % _("Elections")
|
||||
top_space = 0
|
||||
|
||||
def get_filename(self):
|
||||
try:
|
||||
assignment_id = self.kwargs['assignment_id']
|
||||
assignment = Assignment.objects.get(id=assignment_id)
|
||||
filename = u'%s-%s' % (_("Assignment"), assignment.name.replace(' ','_'))
|
||||
except:
|
||||
filename = _("Elections")
|
||||
return filename
|
||||
|
||||
def append_to_pdf(self, story):
|
||||
try:
|
||||
assignment_id = self.kwargs['assignment_id']
|
||||
@ -318,7 +326,6 @@ class AssignmentPDF(PDFView):
|
||||
story = self.get_assignment(assignment, story)
|
||||
else: # print selected assignment
|
||||
assignment = Assignment.objects.get(id=assignment_id)
|
||||
filename = u'filename=%s-%s.pdf;' % (_("Assignment"), assignment.name.replace(' ','_'))
|
||||
story = self.get_assignment(assignment, story)
|
||||
|
||||
def get_assignment(self, assignment, story):
|
||||
@ -458,10 +465,13 @@ class AssignmentPollPDF(PDFView):
|
||||
filename = u'%s-%s-#%s' % (_("Election"), self.poll.assignment.name.replace(' ','_'), 1)#self.poll.get_ballot())
|
||||
return filename
|
||||
|
||||
def append_to_pdf(self, story):
|
||||
#doc = SimpleDocTemplate(response, pagesize=A4, topMargin=-6, bottomMargin=-6, leftMargin=0, rightMargin=0, showBoundary=False)
|
||||
#story = [Spacer(0,0*cm)]
|
||||
def get_template(self, buffer):
|
||||
return SimpleDocTemplate(buffer, topMargin=-6, bottomMargin=-6, leftMargin=0, rightMargin=0, showBoundary=False)
|
||||
|
||||
def build_document(self, pdf_document, story):
|
||||
pdf_document.build(story)
|
||||
|
||||
def append_to_pdf(self, story):
|
||||
imgpath = os.path.join(SITE_ROOT, 'static/images/circle.png')
|
||||
circle = "<img src='%s' width='15' height='15'/> " % imgpath
|
||||
cell = []
|
||||
|
@ -238,22 +238,28 @@ class PDFView(PermissionMixin, View):
|
||||
def get_document_title(self):
|
||||
return self.document_title
|
||||
|
||||
def get_get_filename(self):
|
||||
def get_filename(self):
|
||||
return self.filename
|
||||
|
||||
def get_template(self, buffer):
|
||||
return SimpleDocTemplate(buffer)
|
||||
|
||||
def build_document(self, pdf_document, story):
|
||||
pdf_document.build(story, onFirstPage=firstPage, onLaterPages=laterPages)
|
||||
|
||||
def render_to_response(self, filename):
|
||||
response = HttpResponse(mimetype='application/pdf')
|
||||
filename = u'filename=%s.pdf;' % self.get_filename()
|
||||
response['Content-Disposition'] = filename.encode('utf-8')
|
||||
|
||||
buffer = StringIO()
|
||||
pdf_document = SimpleDocTemplate(buffer)
|
||||
pdf_document = self.get_template(buffer)
|
||||
pdf_document.title = self.get_document_title()
|
||||
story = [Spacer(1, self.get_top_space()*cm)]
|
||||
|
||||
self.append_to_pdf(story)
|
||||
|
||||
pdf_document.build(story, onFirstPage=firstPage, onLaterPages=laterPages)
|
||||
self.build_document(pdf_document, story)
|
||||
|
||||
pdf = buffer.getvalue()
|
||||
buffer.close()
|
||||
|
Loading…
Reference in New Issue
Block a user