Changeset 7304 for main/waeup.sirp/trunk


Ignore:
Timestamp:
7 Dec 2011, 08:53:50 (13 years ago)
Author:
Henrik Bettermann
Message:

Insert container content table on pdf slips. Use this automatic insertion for course ticket lists on ExportPDFCourseRegistrationSlipPages.

ToDo?: The table does not show up if there are too many lines and it thus doesn't fit on the page.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
5 edited

Legend:

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

    r7277 r7304  
    825825        return students_utils.renderPDF(
    826826            self,'Course Registration', 'course_registration.pdf',
    827             self.context.getStudent, studentview)
     827            self.context.getStudent, studentview,
     828            tableheader=[('Code','code'), ('Title','title'),
     829                         ('Department','dcode'), ('Faculty','fcode'),
     830                         ('Credits', 'credits'),
     831                         ('Mandatory', 'core_or_elective'),
     832                         ('Score', 'score'),('Auto', 'automatic')
     833                         ],
     834            tabledata=self.context.values())
    828835
    829836class StudyLevelManageActionButton(ManageActionButton):
     
    919926        ticket.faculty = course.__parent__.__parent__.__parent__.title
    920927        ticket.department = course.__parent__.__parent__.title
     928        ticket.fcode = course.__parent__.__parent__.__parent__.code
     929        ticket.dcode = course.__parent__.__parent__.code
    921930        ticket.credits = course.credits
    922931        ticket.passmark = course.passmark
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7256 r7304  
    328328    faculty = Attribute('faculty of the original course')
    329329    department = Attribute('department of the original course')
     330    fcode = Attribute('faculty code of the original course')
     331    dcode = Attribute('department code of the original course')
    330332
    331333    core_or_elective = schema.Bool(
  • main/waeup.sirp/trunk/src/waeup/sirp/students/studycourse.py

    r7256 r7304  
    6060            ticket.faculty = val.course.__parent__.__parent__.__parent__.title
    6161            ticket.department = val.course.__parent__.__parent__.title
     62            ticket.fcode = val.course.__parent__.__parent__.__parent__.code
     63            ticket.dcode = val.course.__parent__.__parent__.code
    6264            ticket.credits = val.course.credits
    6365            ticket.passmark = val.course.passmark
  • main/waeup.sirp/trunk/src/waeup/sirp/students/studylevel.py

    r7256 r7304  
    7777        self.faculty = None
    7878        self.department = None
     79        self.fcode = None
     80        self.dcode = None
    7981        self.credits = None
    8082        self.passmark = None
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r7280 r7304  
    3737    )
    3838
     39CONTENT_STYLE = TableStyle(
     40    [('VALIGN',(0,0),(-1,-1),'TOP')]
     41    )
     42
    3943def generate_student_id(students,letter):
    4044    if letter == '?':
     
    6771    img = getUtility(IExtFileStore).getFileByContext(
    6872        studentview.context, attr='passport.jpg')
    69     #import pdb; pdb.set_trace()
    7073    if img is None:
    7174        from waeup.sirp.browser import DEFAULT_PASSPORT_IMAGE_PATH
     
    7780        if widget.name == 'form.adm_code':
    7881            continue
    79         f_label = '<font size=12>%s</font>:' % widget.label.strip()
     82        f_label = '<font size=12>%s</font>:' % (
     83            widget.label.strip())
    8084        f_label = Paragraph(f_label, style["Normal"])
    8185        f_text = '<font size=12>%s</font>' % widget()
     
    8387        data.append([f_label,f_text])
    8488    table = Table(data,style=SLIP_STYLE)
     89    return table
     90
     91def render_table_data(tableheader,tabledata):
     92    data = []
     93    data.append([Spacer(1, 12)])
     94    line = []
     95    style = getSampleStyleSheet()
     96    for element in tableheader:
     97        field = '<strong><font size=10>%s</font></strong>' % element[0]
     98        field = Paragraph(field, style["BodyText"])
     99        line.append(field)
     100    data.append(line)
     101    for ticket in tabledata:
     102        line = []
     103        for element in tableheader:
     104              fieldcontent = getattr(ticket,element[1],u' ')
     105              field = '<font size=10>%s</font>' % fieldcontent
     106              field = Paragraph(field, style["BodyText"])
     107              line.append(field)
     108        data.append(line)
     109    # ToDo: The table does not show up if there are too many line
     110    # and it thus doesn't fit on the page
     111    table = Table(data,splitByRow=True,style=CONTENT_STYLE)
    85112    return table
    86113
     
    147174
    148175    def renderPDF(self, view, subject='', filename='slip.pdf',
    149         student=None, studentview=None):
     176        student=None, studentview=None, tableheader=None, tabledata=None):
    150177        # (0,0),(-1,-1) = whole table
    151178        # (0,0),(0,-1) = first column
     
    173200        frame_body = Frame(1*cm,1*cm,width-(2*cm),height-(3.5*cm))
    174201        story.append(Paragraph(view.label, style["Heading2"]))
    175         #story.append(HRFlowable())
     202
     203        # Insert student data table
    176204        if student:
    177205            story.append(Spacer(1, 12))
    178206            studenttable = render_student_data(student, studentview)
    179207            story.append(studenttable)
     208
    180209        story.append(Spacer(1, 12))
    181210        set_up_widgets(view)
     
    218247            view.flash('Error in image file.')
    219248            return view.redirect(view.url(view.context))
     249
     250        # Insert content table
     251        if tabledata and tableheader:
     252            story = []
     253            story.append(Spacer(1, 12))
     254            contenttable = render_table_data(tableheader,tabledata)
     255            story.append(contenttable)
     256            #import pdb; pdb.set_trace()
     257            frame_body.addFromList(story,pdf)
     258
    220259        story = []
    221260        frame_footer = Frame(1*cm,0,width-(2*cm),1*cm)
Note: See TracChangeset for help on using the changeset viewer.