Changeset 12182


Ignore:
Timestamp:
9 Dec 2014, 11:04:53 (10 years ago)
Author:
Henrik Bettermann
Message:

Add PDFMergeDocumentSlipPage which merges the pdf slip with pdf files connected to the document.

Location:
main/waeup.ikoba/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/setup.py

    r12060 r12182  
    4242    'z3c.evalexception',
    4343    'paypalrestsdk',
     44    'PyPDF2',
    4445    ],
    4546
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12169 r12182  
    10291029            omit_fields=self.omit_fields)
    10301030
     1031
     1032class PDFMergeDocumentSlipPage(PDFDocumentSlipPage):
     1033    """Deliver pdf file including metadata.
     1034    """
     1035    grok.context(ICustomerPDFDocument)
     1036
     1037    def render(self):
     1038        portal_language = getUtility(IIkobaUtils).PORTAL_LANGUAGE
     1039        customerview = CustomerBasePDFFormPage(self.context.customer,
     1040            self.request, self.omit_fields)
     1041        customers_utils = getUtility(ICustomersUtils)
     1042        return customers_utils.renderPDF(
     1043            self, 'pdfdocument_slip.pdf',
     1044            self.context.customer, customerview,
     1045            omit_fields=self.omit_fields,
     1046            mergefiles=self.context.connected_files)
     1047
    10311048# Pages for customer contracts
    10321049
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12169 r12182  
    10911091        open(path, 'wb').write(self.browser.contents)
    10921092        print "Sample document_slip.pdf written to %s" % path
     1093        # Officers can open merged pdf document slips
     1094        pdfdocument = createObject('waeup.CustomerPDFDocument')
     1095        pdfdocument.title = u'My first document'
     1096        self.customer['documents'].addDocument(pdfdocument)
     1097        # Add pdf file
     1098        file_id = IFileStoreNameChooser(pdfdocument).chooseName(attr='sample.pdf')
     1099        fs = ExtFileStore(root=self.dc_root)
     1100        pdffile = open(SAMPLE_PDF, 'rb')
     1101        fs.createFile(file_id, pdffile)
     1102        self.browser.open(self.customer_path + '/documents/d102')
     1103        self.browser.getLink("Download document slip").click()
     1104        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1105        self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf')
     1106        path = os.path.join(samples_dir(), 'pdfdocument_slip.pdf')
     1107        open(path, 'wb').write(self.browser.contents)
     1108        print "Sample pdfdocument_slip.pdf written to %s" % path
    10931109
    10941110
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py

    r12099 r12182  
    2121import os
    2222import grok
     23from StringIO import StringIO
    2324from reportlab.lib import colors
    2425from reportlab.lib.units import cm
     
    2627from reportlab.lib.styles import getSampleStyleSheet
    2728from reportlab.platypus import Paragraph, Image, Table, Spacer
     29from reportlab.platypus.flowables import PageBreak
     30from PyPDF2 import PdfFileMerger, PdfFileReader, PdfFileWriter
    2831from zope.event import notify
    2932from zope.schema.interfaces import ConstraintNotSatisfied
     
    334337                  note=None, signatures=None, sigs_in_footer=(),
    335338                  show_scans=True, show_history=True, topMargin=1.5,
    336                   omit_fields=()):
     339                  omit_fields=(), mergefiles=None):
    337340        """Render pdf slips for various pages.
    338341        """
     
    419422            view.flash('Error in image file.')
    420423            return view.redirect(view.url(view.context))
     424
     425        if mergefiles:
     426            merger = PdfFileMerger()
     427            merger.append(StringIO(pdf_stream))
     428            for file in mergefiles:
     429                merger.append(file[1])
     430            tmp = StringIO()
     431            merger.write(tmp)
     432            return tmp.getvalue()
     433
    421434        return pdf_stream
  • main/waeup.ikoba/trunk/versions.cfg

    r12170 r12182  
    177177# paypalrestsdk==1.6.1
    178178requests = 2.4.3
     179
     180# Added by buildout at 2014-12-09 08:56:22.978680
     181
     182# Required by:
     183# waeup.ikoba==0.2dev
     184PyPDF2 = 1.23
Note: See TracChangeset for help on using the changeset viewer.