Changeset 16262 for main


Ignore:
Timestamp:
1 Oct 2020, 06:51:10 (4 years ago)
Author:
Henrik Bettermann
Message:

Use Uli's marker substitution hack to inject signature
images into pdf files.

Location:
main/waeup.kofa/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r16251 r16262  
    441.6.1.dev0 (unreleased)
    55=======================
     6
     7* Use Uli's marker substitution hack to inject signature
     8  images into pdf files.
    69
    710* Implement `ExportPDFPersonalDataSlip` (without button
  • main/waeup.kofa/trunk/src/waeup/kofa/browser/pdf.py

    r16149 r16262  
    2323import os
    2424import pytz
     25from string import Template
    2526from cStringIO import StringIO
    2627from datetime import datetime
     
    559560    logo_left_pos = [0, 0, 0]
    560561    pagesize = portrait(A4)
     562
     563    test_signature_img_path = os.path.join(
     564        os.path.dirname(__file__), 'static', 'test_signature.png')
    561565
    562566    @classmethod
     
    823827        return
    824828
     829    def _substitute_markers(self, text):
     830        """If `text` contains some marker, substitute it.
     831
     832        Markers are standard library string template placeholders. See
     833        https://docs.python.org/2/library/string.html and
     834        `string.Template` for details. Roughly, placeholders look like
     835        ``${some_marker}``.
     836
     837        Valid markers:
     838           ``test_signature_img_path`` -- path to signature image stored in
     839                                     `test_signature_img_path`` attribute.
     840        """
     841        text = Template(text)
     842        PDF_SIGNATURES =  {
     843            'test_signature_img_path': self.test_signature_img_path,
     844            }
     845        return text.safe_substitute(PDF_SIGNATURES)
     846
    825847    def create_pdf(self, data, headerline=None, title=None, author=None,
    826848                   footer='', note=None, sigs_in_footer=[], topMargin=1.5,
     
    849871        doc.letterhead_path = letterhead_path
    850872        if note is not None:
     873            # Inject signature images
     874            note = self._substitute_markers(note)
     875            # Format html
    851876            html = format_html(note)
    852877            data.append(Paragraph(html, NOTE_STYLE))
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r16251 r16262  
    539539    form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number')
    540540
     541
     542    # Can be used for testing. Just replace 'post_text=None'
     543    # by post_text=self.post_text'
     544    post_text = '''
     545Conratulations!
     546
     547
     548<img src="${test_signature_img_path}" valign="-20" height="38" width="86" />
     549
     550
     551John Tester
     552- Registrar -
     553'''
     554
    541555    @property
    542556    def label(self):
     
    554568        return students_utils.renderPDFAdmissionLetter(self,
    555569            self.context.student, omit_fields=self.omit_fields,
    556             letterhead_path=letterhead_path)
     570            letterhead_path=letterhead_path, post_text=None)
    557571
    558572class StudentBaseManageFormPage(KofaEditFormPage):
Note: See TracChangeset for help on using the changeset viewer.