Changeset 11878 for main/waeup.kwarapoly


Ignore:
Timestamp:
27 Oct 2014, 23:26:21 (10 years ago)
Author:
uli
Message:

Make the signature appear in admission notification PDF.

Location:
main/waeup.kwarapoly/branches/uli-pdfsigs/src/waeup/kwarapoly
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kwarapoly/branches/uli-pdfsigs/src/waeup/kwarapoly/browser/pdf.py

    r10145 r11878  
    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)
  • main/waeup.kwarapoly/branches/uli-pdfsigs/src/waeup/kwarapoly/students/browser.py

    r11873 r11878  
    37637614. You possess the entry requirement for the programme you are admitted.<br /><br />
    377377
     378<img src="${signature_img_path}" valign="middle"  height="45.8mm" width="20mm" /><br />
    378379M.O. Adebayo<br />
    379380Admission Officer<br />
    380381For: Registrar
    381382"""
     383# XXX: a note for <img /> tag used here (from reportlab docs):
     384#   The valign attribute may be set to a css like value from "baseline", "sub",
     385#   "super", "top", "text-top", "middle", "bottom", "text-bottom";
     386#   the value may also be a numeric percentage or an absolute value.
     387#
     388# Burn this remark after reading.
Note: See TracChangeset for help on using the changeset viewer.