Ignore:
Timestamp:
13 Jun 2011, 07:34:17 (14 years ago)
Author:
Henrik Bettermann
Message:

Further pdf improvements (in progress): Show data in table layout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py

    r6360 r6363  
    529529    grok.require('waeup.handleApplication')
    530530    icon = 'actionicon_pdf.png'
    531     text = 'Download pdf slip'
     531    text = 'Application slip'
    532532    target = 'application_slip.pdf'
    533533
     
    540540    form_fields = grok.AutoFields(IApplicant).omit(
    541541        'locked').omit('course_admitted')
    542     #form_fields['passport'].custom_widget = ThumbnailWidget
    543542    form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
    544 
    545543    prefix = 'form'
     544
     545    @property
     546    def label(self):
     547        container_title = self.context.__parent__.title
     548        return '%s Application Record' % container_title
    546549
    547550    def getCourseAdmitted(self):
     
    564567            )
    565568
    566     # Render a demo pdf page
    567569    def render(self):
    568570        from reportlab.pdfgen import canvas
     
    570572        from reportlab.lib.pagesizes import A4, landscape
    571573        from reportlab.lib.styles import getSampleStyleSheet
    572         from reportlab.platypus import Frame, Paragraph, Image
     574        from reportlab.platypus import (Frame, Paragraph, Image,
     575            Table, Spacer)
     576        from reportlab.platypus.flowables import HRFlowable
    573577
    574578        pdf = canvas.Canvas('application_slip.pdf',pagesize=A4)
    575579        width, height = A4
    576580        style = getSampleStyleSheet()
     581
    577582        story = []
    578         frame = Frame(1*cm,1*cm,width-(2*cm),height-(2*cm))
     583        frame_header = Frame(1*cm,1*cm,width-(4*cm),height-(1*cm))
     584        header_title = getattr(grok.getSite(), 'name', u'Sample University')
     585        story.append(Paragraph(header_title, style["Heading1"]))
     586        #import pdb; pdb.set_trace()
     587        frame_header.addFromList(story,pdf)
     588
     589        story = []
     590        frame_body = Frame(1*cm,1*cm,width-(4*cm),height-(3*cm))
     591        story.append(Paragraph(self.label, style["Title"]))
     592        story.append(HRFlowable())
     593        story.append(Spacer(1, 24))
     594
    579595        self.setUpWidgets()
    580        
     596
     597        data = []
    581598        for widget in self.widgets:
     599            f_label = '<font size=12>%s</font>' % widget.label.strip()
     600            f_label = Paragraph(f_label, style["Normal"])
    582601            if widget.name != 'form.passport':
    583                 ptext = widget()
    584                 story.append(Paragraph(ptext, style["Normal"]))
     602                f_text = '<font size=12>%s</font>' % widget()
     603                f_text = Paragraph(f_text, style["Normal"])
     604                data.append([f_label,f_text])
    585605            else:
    586                 #import pdb; pdb.set_trace()
    587606                filename = widget._data.file.name
    588607                im = Image(filename)
    589                 story.append(im)
    590         frame.addFromList(story,pdf)
     608                data.append([f_label,im])
     609        f_label = '<font size=12>Admitted Course of Study</font>'
     610        f_text = '<font size=12>%s</font>' % self.getCourseAdmitted()
     611        f_label = Paragraph(f_label, style["Normal"])
     612        f_text = Paragraph(f_text, style["Normal"])
     613        data.append([f_label,f_text])
     614        table = Table(data)
     615        story.append(table)
     616        frame_body.addFromList(story,pdf)
     617
    591618        self.response.setHeader(
    592619            'Content-Type', 'application/pdf')
Note: See TracChangeset for help on using the changeset viewer.