Ignore:
Timestamp:
28 Mar 2014, 08:54:30 (11 years ago)
Author:
Henrik Bettermann
Message:

Print QR codes on all student slips.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r11535 r11550  
    3838from waeup.kofa.browser.pdf import (
    3939    ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE,
    40     get_signature_tables)
     40    get_signature_tables, get_qrcode)
    4141from waeup.kofa.browser.interfaces import IPDFCreator
    4242from waeup.kofa.utils.helpers import to_timezone
     
    105105        )
    106106
    107 def render_student_data(studentview, omit_fields=(), lang='en'):
     107def render_student_data(studentview, context, omit_fields=(),
     108                        lang='en', slipname=None):
    108109    """Render student table for an existing frame.
    109110    """
     
    111112    set_up_widgets(studentview, ignore_request=True)
    112113    data_left = []
    113     data_right = []
     114    data_middle = []
    114115    style = getSampleStyleSheet()
    115116    img = getUtility(IExtFileStore).getFileByContext(
     
    126127    f_text = formatted_text(studentview.context.display_fullname)
    127128    f_text = Paragraph(f_text, ENTRY1_STYLE)
    128     data_right.append([f_label,f_text])
     129    data_middle.append([f_label,f_text])
    129130
    130131    for widget in studentview.widgets:
     
    137138        f_text = formatted_text(widget(), lang=lang)
    138139        f_text = Paragraph(f_text, ENTRY1_STYLE)
    139         data_right.append([f_label,f_text])
     140        data_middle.append([f_label,f_text])
    140141
    141142    if getattr(studentview.context, 'certcode', None):
     
    146147                studentview.context['studycourse'].certificate.longtitle)
    147148            f_text = Paragraph(f_text, ENTRY1_STYLE)
    148             data_right.append([f_label,f_text])
     149            data_middle.append([f_label,f_text])
    149150        if not 'department' in omit_fields:
    150151            f_label = trans(_('Department:'), lang)
     
    155156                )
    156157            f_text = Paragraph(f_text, ENTRY1_STYLE)
    157             data_right.append([f_label,f_text])
     158            data_middle.append([f_label,f_text])
    158159        if not 'faculty' in omit_fields:
    159160            f_label = trans(_('Faculty:'), lang)
     
    164165                )
    165166            f_text = Paragraph(f_text, ENTRY1_STYLE)
    166             data_right.append([f_label,f_text])
     167            data_middle.append([f_label,f_text])
    167168        if not 'current_mode' in omit_fields:
    168169            studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
     
    172173            f_text = formatted_text(sm)
    173174            f_text = Paragraph(f_text, ENTRY1_STYLE)
    174             data_right.append([f_label,f_text])
     175            data_middle.append([f_label,f_text])
    175176        if not 'entry_session' in omit_fields:
    176177            f_label = trans(_('Entry Session:'), lang)
     
    180181            f_text = formatted_text(entry_session)
    181182            f_text = Paragraph(f_text, ENTRY1_STYLE)
    182             data_right.append([f_label,f_text])
     183            data_middle.append([f_label,f_text])
    183184        # Requested by Uniben, does not really make sense
    184185        if not 'current_level' in omit_fields:
     
    191192            f_text = formatted_text(current_level)
    192193            f_text = Paragraph(f_text, ENTRY1_STYLE)
    193             data_right.append([f_label,f_text])
     194            data_middle.append([f_label,f_text])
    194195        if not 'date_of_birth' in omit_fields:
    195196            f_label = trans(_('Date of Birth:'), lang)
     
    202203            f_text = formatted_text(date_of_birth)
    203204            f_text = Paragraph(f_text, ENTRY1_STYLE)
    204             data_right.append([f_label,f_text])
     205            data_middle.append([f_label,f_text])
     206
     207    # append QR code to the right
     208    if slipname:
     209        url = studentview.url(context, slipname)
     210        data_right = [[get_qrcode(url, width=70.0)]]
     211        table_right = Table(data_right,style=SLIP_STYLE)
     212    else:
     213        table_right = None
    205214
    206215    table_left = Table(data_left,style=SLIP_STYLE)
    207     table_right = Table(data_right,style=SLIP_STYLE, colWidths=[5*cm, 6*cm])
    208     table = Table([[table_left, table_right],],style=SLIP_STYLE)
     216    table_middle = Table(data_middle,style=SLIP_STYLE, colWidths=[5*cm, 5*cm])
     217    table = Table([[table_left, table_middle, table_right],],style=SLIP_STYLE)
    209218    return table
    210219
     
    589598
    590599        # Student data
    591         data.append(render_student_data(view, omit_fields, lang=portal_language))
     600        data.append(render_student_data(view, student,
     601                    omit_fields, lang=portal_language,
     602                    slipname='admission_slip.pdf'))
    592603
    593604        # Text after student data
     
    649660            data.append(Paragraph(bd_translation, HEADING_STYLE))
    650661            data.append(render_student_data(
    651                 studentview, omit_fields, lang=portal_language))
     662                studentview, view.context, omit_fields, lang=portal_language,
     663                slipname=filename))
    652664
    653665        # Insert widgets
     
    757769            #data.append(Paragraph(bd_translation, HEADING_STYLE))
    758770            data.append(render_student_data(
    759                 studentview, omit_fields, lang=portal_language))
    760 
     771                studentview, view.context,
     772                omit_fields, lang=portal_language,
     773                slipname=filename))
    761774
    762775        transcript_data = view.context.getTranscriptData()
Note: See TracChangeset for help on using the changeset viewer.