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:
4 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)
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/browser.py

    r11873 r11887  
    5656    )
    5757
     58
    5859class CustomStudentBaseEditFormPage(NigeriaStudentBaseEditFormPage):
    5960    """ View to edit student base data
     
    6263        'email', 'phone', 'sex')
    6364
    64 class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage):
     65
     66class CustomStudentPersonalDisplayFormPage(
     67    NigeriaStudentPersonalDisplayFormPage):
    6568    """ Page to display student personal data
    6669    """
     
    7376        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    7477
     78
    7579class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
    7680    """ Page to edit personal data
     
    7983        'personal_updated')
    8084
    81 class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage):
     85
     86class CustomStudentPersonalManageFormPage(
     87    NigeriaStudentPersonalManageFormPage):
    8288    """ Page to edit personal data
    8389    """
     
    8692    form_fields[
    8793        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     94
    8895
    8996class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
     
    98105        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    99106
     107
    100108class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
    101109    """ Page to add an online payment ticket
     
    103111    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
    104112        'p_category')
     113
    105114
    106115class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
     
    110119    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
    111120        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
    112     form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
    113     form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     121    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget(
     122        'le')
     123    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget(
     124        'le')
     125
    114126
    115127class CustomStartClearancePage(StartClearancePage):
     
    118130
    119131
    120 class CustomStudentClearanceDisplayFormPage(NigeriaStudentClearanceDisplayFormPage):
     132class CustomStudentClearanceDisplayFormPage(
     133    NigeriaStudentClearanceDisplayFormPage):
    121134    """ Page to display student clearance data
    122135    """
     
    135148            form_fields['officer_comment'].custom_widget = BytesDisplayWidget
    136149        return form_fields
     150
    137151
    138152class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
     
    152166        return form_fields
    153167
    154 class CustomStudentClearanceManageFormPage(NigeriaStudentClearanceManageFormPage):
     168
     169class CustomStudentClearanceManageFormPage(
     170    NigeriaStudentClearanceManageFormPage):
    155171    """ Page to edit student clearance data
    156172    """
     
    165181                ICustomUGStudentClearance).omit('clr_code')
    166182        return form_fields
     183
    167184
    168185class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
     
    183200        return form_fields
    184201
     202
    185203class BedTicketAddPage(BedTicketAddPage):
    186204    """ Page to add an online payment ticket
     
    190208    with_ac = False
    191209
     210
    192211class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage):
    193212    """Deliver a PDF Admission slip.
     
    197216    omit_fields = ('date_of_birth', 'current_level')
    198217
    199     form_fields = grok.AutoFields(ICustomStudent).select('student_id', 'reg_number')
     218    form_fields = grok.AutoFields(ICustomStudent).select(
     219        'student_id', 'reg_number')
    200220
    201221    def render(self):
     
    208228        return students_utils.renderPDFAdmissionLetter(self,
    209229            self.context.student, omit_fields=self.omit_fields)
     230
    210231
    211232class ExportPDFAdmissionNotificationPage(UtilityView, grok.View):
     
    235256            pre_text=pre_text, post_text=post_text)
    236257
     258
    237259# copied from waeup.aaue
    238260class CustomExportPDFCourseRegistrationSlipPage(
     
    262284             'I recommend to approve the course registration. <br>',
    263285             _('Head of Department\'s Signature'), '<br>')],
    264             [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
     286            [('', _('Principal Assistant Registrar\'s Signature'), '<br>')],
    265287            [('', _('Director\'s Signature'))]
    266288            )
     
    270292        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
    271293        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
    272         Title = translate('Title', 'waeup.kofa', target_language=portal_language)
    273         Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
    274         Score = translate('Score', 'waeup.kofa', target_language=portal_language)
    275         Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
     294        Title = translate('Title', 'waeup.kofa',
     295                          target_language=portal_language)
     296        Cred = translate(
     297            'Cred.', 'waeup.kofa', target_language=portal_language)
     298        Score = translate('Score', 'waeup.kofa',
     299                          target_language=portal_language)
     300        Grade = translate('Grade', 'waeup.kofa',
     301                          target_language=portal_language)
    276302        Signature = translate(_('HOD\'s Signature'), 'waeup.kwarapoly',
    277303            target_language=portal_language)
     
    283309        tableheader = []
    284310        contenttitle = []
    285         for i in range(1,7):
     311        for i in range(1, 7):
    286312            tabledata.append(sorted(
    287                 [value for value in self.context.values() if value.semester == i],
     313                [value for value in self.context.values()
     314                 if value.semester == i],
    288315                key=lambda value: str(value.semester) + value.code))
    289             tableheader.append([(Code,'code', 2.0),
    290                                (Title,'title', 7),
     316            tableheader.append([(Code, 'code', 2.0),
     317                               (Title, 'title', 7),
    291318                               (Cred, 'credits', 1.5),
    292319                               (Score, 'score', 1.4),
     
    310337            )
    311338
     339
    312340class ExportPDFRegistrationSlipPage(grok.View):
    313341    """Deliver a PDF slip of the context.
     
    343371<strong>IMPORTANT NOTICE</strong>
    344372<br /><br />
    345 This registration slip must be supplied before attendance of lectures. Note that:<br /><br />
    346 1. All fees due must be paid in full.<br /><br />
    347 2. All information required must be available on the Registration Form.<br /><br />
    348 3. The Signature of all appropriate Polytechnic Authority must be obtained.<br /><br />
    349 4. The endorsed Registration Form should be returned to the respective Institutes and Administrative Offices.<br /><br />
    350 5. No student may change his subject or course of study as shown in the signed Registration Form without clearance from the Admissions Office and the Director of the appropriate Institute.<br /><br />
    351 6. All candidates admitted into the HND I programmes should submit the photocopies of their original certificates of ND and SSCE with scratch card online for clearance latest a week after the admission is offered. Failure to comply with this directive may lead to the forfeiture of the admission.<br /><br />
    352 
     373This registration slip must be supplied before attendance of lectures.
     374Note that:
     375<br /><br />
     3761. All fees due must be paid in full.
     377<br /><br />
     3782. All information required must be available on the Registration Form.
     379<br /><br />
     3803. The Signature of all appropriate Polytechnic Authority must be obtained.
     381<br /><br />
     3824. The endorsed Registration Form should be returned to the respective
     383   Institutes and Administrative Offices.
     384<br /><br />
     3855. No student may change his subject or course of study as shown in the
     386   signed Registration Form without clearance from the Admissions Office
     387   and the Director of the appropriate Institute.
     388<br /><br />
     3896. All candidates admitted into the HND I programmes should submit the
     390   photocopies of their original certificates of ND and SSCE with scratch
     391   card online for clearance latest a week after the admission is offered.
     392   Failure to comply with this directive may lead to the forfeiture of
     393   the admission.
     394<br /><br />
     395<!-- image size: 229x100 pixels; ratio (2.29:1) must be kept -->
     396<img src="${signature_img_path}" valign="-30"
     397     height="75" width="172" />
     398<br />
    353399M.O. Adebayo<br />
    354400Admission Officer<br />
     
    359405<strong>INSTRUCTIONS TO FRESHERS</strong>
    360406<br /><br />
    361 You are hereby offered a provisional admission for the 2014/2015 session subject to the conditions that:
    362 <br /><br />
    363 1. The information given in your Application Form is correct.<br /><br />
    364 2. The original of your Credentials are presented for scrutiny.<br /><br />
    365 3. If at any time the Credentials submitted are found to be false/fake or incorrect, your admission shall be withdrawn.<br /><br />
    366 4. The name by which you are admitted and registered shall remain same throughout the duration of your programme.<br /><br />
    367 5. You are to fill and submit the Undertaking Form at the point of registration failure which your admission will be forfeited.<br /><br />
    368 6. You will dress decently covering your nakedness at all times.<br /><br />
    369 7. Payment of school fees will be once and in full and should be by Interswitch to the designated Banks. Failure to pay fees by the mode mentioned above by the closing date means you have declined the offer and your place will be given to another eligible candidate immediately.<br /><br />
    370 8. You present a Certificate of medical fitness from the Polytechnic Clinic.<br /><br />
    371 9. All indigenes of Kwara State are required to present Certificate of Citizenship.<br /><br />
    372 10. The Polytechnic reserves the right to withdraw your admission at any stage, if you are found to be a cultist or an expelled individual from any tertiary institution.<br /><br />
    373 11. You are prepared to take up accommodation provided on the campuses by the authority.<br /><br />
    374 12. There will be no refund of school fees once paid.<br /><br />
    375 13. If you accept this offer with the above stated conditions, please make a photocopy of this document and return it to the Admission Office immediately.<br /><br />
    376 14. You possess the entry requirement for the programme you are admitted.<br /><br />
    377 
     407You are hereby offered a provisional admission for the 2014/2015 session
     408subject to the conditions that:
     409<br /><br />
     4101. The information given in your Application Form is correct.
     411<br /><br />
     4122. The original of your Credentials are presented for scrutiny.
     413<br /><br />
     4143. If at any time the Credentials submitted are found to be false/fake
     415   or incorrect, your admission shall be withdrawn.
     416<br /><br />
     4174. The name by which you are admitted and registered shall remain same
     418   throughout the duration of your programme.
     419<br /><br />
     4205. You are to fill and submit the Undertaking Form at the point of
     421   registration failure which your admission will be forfeited.
     422<br /><br />
     4236. You will dress decently covering your nakedness at all times.
     424<br /><br />
     4257. Payment of school fees will be once and in full and should be by
     426   Interswitch to the designated Banks. Failure to pay fees by the
     427   mode mentioned above by the closing date means you have declined
     428   the offer and your place will be given to another eligible
     429   candidate immediately.
     430<br /><br />
     4318. You present a Certificate of medical fitness from the Polytechnic
     432   Clinic.
     433<br /><br />
     4349. All indigenes of Kwara State are required to present Certificate of
     435   Citizenship.
     436<br /><br />
     43710. The Polytechnic reserves the right to withdraw your admission at
     438    any stage, if you are found to be a cultist or an expelled
     439    individual from any tertiary institution.
     440<br /><br />
     44111. You are prepared to take up accommodation provided on the campuses
     442    by the authority.
     443<br /><br />
     44412. There will be no refund of school fees once paid.
     445<br /><br />
     44613. If you accept this offer with the above stated conditions, please
     447    make a photocopy of this document and return it to the Admission
     448    Office immediately.
     449<br /><br />
     45014. You possess the entry requirement for the programme you are admitted.
     451<br /><br />
     452
     453<!-- image size: 229x100 pixels; ratio (2.29:1) must be kept -->
     454<img src="${signature_img_path}" valign="-30"
     455     height="75" width="172" />
     456<br />
    378457M.O. Adebayo<br />
    379458Admission Officer<br />
    380459For: Registrar
    381460"""
     461# XXX: a note for <img /> tag used here (from reportlab docs):
     462#   The valign attribute may be set to a css like value from "baseline", "sub",
     463#   "super", "top", "text-top", "middle", "bottom", "text-bottom";
     464#   the value may also be a numeric percentage or an absolute value.
     465#
     466# Burn this remark after reading.
Note: See TracChangeset for help on using the changeset viewer.