Ignore:
Timestamp:
28 Oct 2014, 17:48:22 (10 years ago)
Author:
uli
Message:

Merge uli-pdfsigs back into trunk.

Location:
main/waeup.kwarapoly/trunk
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • main/waeup.kwarapoly/trunk

  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly

  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/browser/pdf.py

    r10145 r11887  
    2121
    2222import os
     23from string import Template
    2324from waeup.kofa.browser.pdf import PDFCreator
    2425
     
    3435    #watermark_pos = [-25, 100]
    3536    logo_pos = [507, 740, 70]
     37
     38    signature_img_path = os.path.join(
     39        os.path.dirname(__file__), 'static', 'pdf_signature.png')
     40
     41    def substitute_markers(self, text):
     42        """If `text` contains some marker, substitute it.
     43
     44        Markers are standard library string template placeholders. See
     45        https://docs.python.org/2/library/string.html and
     46        `string.Template` for details. Roughly, placeholders look like
     47        ``${some_marker}``.
     48
     49        Valid markers:
     50           ``signature_img_path`` -- path to signature image stored in
     51                                     `signature_img_path`` attribute.
     52        """
     53        text = Template(text)
     54        return text.safe_substitute(
     55            {
     56                'signature_img_path': self.signature_img_path,
     57                }
     58            )
     59
     60    def create_pdf(self, *args, **kw):
     61        """Create PDF from args and keywords.
     62
     63        Unlike the base method, we mangle any `notes` keyword and
     64        substitute any valid placeholder strings in it. See
     65        `substitute_markers` for a list of valid placeholders.
     66
     67        XXX: This is only a quick, dirty hack, that should not appear
     68             in this package. Instead it should be moved to the
     69             waeup.kofa basepackage.
     70
     71        Please note: string substitution like this can introduce nasty
     72        security holes. For instance all dynamic input in `notes` must
     73        be cleaned up and placeholder expressions should be removed
     74        from it before using it in `note`.
     75
     76        Also, `note` is clearly misused in this case. We might want to
     77        look for a more general approach, maybe z3c.rml?
     78        """
     79        if 'note' in kw.keys() and kw['note'] is not None:
     80            kw['note'] = self.substitute_markers(kw['note'])
     81        return super(CustomPDFCreator, self).create_pdf(*args, **kw)
Note: See TracChangeset for help on using the changeset viewer.