Ignore:
Timestamp:
6 Nov 2012, 07:48:28 (12 years ago)
Author:
Henrik Bettermann
Message:

Customize render method of view instead of renderPDF method of global utility.

Location:
main/waeup.uniben/trunk/src/waeup/uniben/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py

    r9439 r9551  
    2727from waeup.kofa.students.browser import (
    2828    StudentClearPage, StudentRejectClearancePage,
    29     StudyLevelEditFormPage,
     29    StudyLevelEditFormPage, StudentBasePDFFormPage,
    3030    msave, emit_lock_message)
     31from waeup.kofa.students.interfaces import IStudentsUtils
    3132from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
    3233from kofacustom.nigeria.students.browser import (
     
    3637    NigeriaOnlinePaymentAddFormPage,
    3738    NigeriaExportPDFPaymentSlipPage,
     39    NigeriaExportPDFClearanceSlipPage,
    3840    )
    39 #from waeup.uniben.students.interfaces import ICustomStudent
    4041
    4142from waeup.uniben.students.interfaces import (
     
    126127#        return
    127128
     129class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
     130    """Deliver a PDF slip of the context.
     131    """
     132
     133    def render(self):
     134        studentview = StudentBasePDFFormPage(self.context.student,
     135            self.request, self.omit_fields)
     136        students_utils = getUtility(IStudentsUtils)
     137        return students_utils.renderPDF(
     138            self, 'clearance_slip.pdf',
     139            self.context.student, studentview, signatures=self._signatures(),
     140            sig_in_footer=self._sigInFooter(), show_scans=False)
     141
    128142class StudyCourseCOEditFormPage(KofaEditFormPage):
    129143    """ Page to edit the student study course data by clearance officers.
  • main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py

    r9549 r9551  
    207207        return None, payment
    208208
    209     def renderPDF(self, view, filename='slip.pdf', student=None,
    210                   studentview=None, tableheader=None, tabledata=None,
    211                   note=None, signatures=None, sig_in_footer=False):
    212         """Render pdf slips for various pages.
    213         """
    214         # XXX: we have to fix the import problems here.
    215         from waeup.kofa.browser.interfaces import IPDFCreator
    216         from waeup.kofa.browser.pdf import NORMAL_STYLE, ENTRY1_STYLE
    217         style = getSampleStyleSheet()
    218         creator = getUtility(IPDFCreator)
    219         data = []
    220         doc_title = view.label
    221         author = '%s (%s)' % (view.request.principal.title,
    222                               view.request.principal.id)
    223         footer_text = view.label
    224         if getattr(student, 'student_id', None) is not None:
    225             footer_text = "%s - %s - " % (student.student_id, footer_text)
    226 
    227         # Insert student data table
    228         portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    229         if student is not None:
    230             bd_translation = trans(_('Base Data'), portal_language)
    231             data.append(Paragraph(bd_translation, style["Heading3"]))
    232             data.append(render_student_data(studentview))
    233 
    234         # Insert widgets
    235         if view.form_fields:
    236             data.append(Paragraph(view.title, style["Heading3"]))
    237             portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    238             separators = getattr(self, 'SEPARATORS_DICT', {})
    239             table = creator.getWidgetsTable(
    240                 view.form_fields, view.context, None, lang=portal_language,
    241                 separators=separators)
    242             data.append(table)
    243 
    244         # Insert scanned docs
    245         #data.extend(docs_as_flowables(view, portal_language))
    246 
    247         # Insert history
    248         if filename.startswith('clearance') or filename.startswith('course'):
    249             hist_translation = trans(_('Workflow History'), portal_language)
    250             data.append(Paragraph(hist_translation, style["Heading3"]))
    251             data.extend(creator.fromStringList(student.history.messages))
    252 
    253        # Insert content table (optionally on second page)
    254         if tabledata and tableheader:
    255             #data.append(PageBreak())
    256             data.append(Spacer(1, 20))
    257             data.append(Paragraph(view.content_title, style["Heading3"]))
    258             contenttable = render_table_data(tableheader,tabledata)
    259             data.append(contenttable)
    260 
    261         # Insert signatures
    262         if signatures and not sig_in_footer:
    263             data.append(Spacer(1, 20))
    264             signaturetable = get_signature_table(signatures)
    265             data.append(signaturetable)
    266 
    267         view.response.setHeader(
    268             'Content-Type', 'application/pdf')
    269         try:
    270             pdf_stream = creator.create_pdf(
    271                 data, None, doc_title, author=author, footer=footer_text,
    272                 note=note, sig_in_footer=sig_in_footer)
    273         except IOError:
    274             view.flash('Error in image file.')
    275             return view.redirect(view.url(view.context))
    276         return pdf_stream
    277 
    278209    # Uniben prefix
    279210    STUDENT_ID_PREFIX = u'B'
Note: See TracChangeset for help on using the changeset viewer.