Changeset 10261


Ignore:
Timestamp:
31 May 2013, 06:38:59 (11 years ago)
Author:
Henrik Bettermann
Message:

Add sessional GPAs to transcript pdf slip.

Fix localization.

File:
1 edited

Legend:

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

    r10256 r10261  
    6262    return translate(text, 'waeup.kofa', target_language=lang)
    6363
    64 def formatted_text(text, color=FONT_COLOR):
     64def formatted_text(text, color=FONT_COLOR, lang='en'):
    6565    """Turn `text`, `color` and `size` into an HTML snippet.
    6666
     
    7676    The returned snippet is unicode type.
    7777    """
    78     try:
    79         # In unit tests IKofaUtils has not been registered
    80         portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    81     except:
    82         portal_language = 'en'
    8378    if not isinstance(text, unicode):
    8479        if isinstance(text, basestring):
     
    9085    # Mainly for boolean values we need our customized
    9186    # localisation of the zope domain
    92     text = translate(text, 'zope', target_language=portal_language)
     87    text = translate(text, 'zope', target_language=lang)
    9388    text = text.replace('</div>', '<br /></div>')
    9489    tag1 = u'<font color="%s">' % (color)
     
    108103        )
    109104
    110 def render_student_data(studentview, omit_fields=()):
     105def render_student_data(studentview, omit_fields=(), lang='en'):
    111106    """Render student table for an existing frame.
    112107    """
     
    124119    data_left.append([doc_img])
    125120    #data.append([Spacer(1, 12)])
    126     portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    127 
    128     f_label = _('Name:')
     121
     122    f_label = trans(_('Name:'), lang)
    129123    f_label = Paragraph(f_label, ENTRY1_STYLE)
    130124    f_text = formatted_text(studentview.context.display_fullname)
     
    137131        f_label = translate(
    138132            widget.label.strip(), 'waeup.kofa',
    139             target_language=portal_language)
     133            target_language=lang)
    140134        f_label = Paragraph('%s:' % f_label, ENTRY1_STYLE)
    141         f_text = formatted_text(widget())
     135        f_text = formatted_text(widget(), lang=lang)
    142136        f_text = Paragraph(f_text, ENTRY1_STYLE)
    143137        data_right.append([f_label,f_text])
     
    145139    if getattr(studentview.context, 'certcode', None):
    146140        if not 'certificate' in omit_fields:
    147             f_label = _('Study Course:')
     141            f_label = trans(_('Study Course:'), lang)
    148142            f_label = Paragraph(f_label, ENTRY1_STYLE)
    149143            f_text = formatted_text(
     
    152146            data_right.append([f_label,f_text])
    153147        if not 'department' in omit_fields:
    154             f_label = _('Department:')
     148            f_label = trans(_('Department:'), lang)
    155149            f_label = Paragraph(f_label, ENTRY1_STYLE)
    156150            f_text = formatted_text(
     
    161155            data_right.append([f_label,f_text])
    162156        if not 'faculty' in omit_fields:
    163             f_label = _('Faculty:')
     157            f_label = trans(_('Faculty:'), lang)
    164158            f_label = Paragraph(f_label, ENTRY1_STYLE)
    165159            f_text = formatted_text(
     
    170164            data_right.append([f_label,f_text])
    171165        if not 'entry_session' in omit_fields:
    172             f_label = _('Entry Session: ')
     166            f_label = trans(_('Entry Session:'), lang)
    173167            f_label = Paragraph(f_label, ENTRY1_STYLE)
    174168            entry_session = studentview.context['studycourse'].entry_session
     
    178172            data_right.append([f_label,f_text])
    179173        if not 'date_of_birth' in omit_fields:
    180             f_label = _('Date of Birth: ')
     174            f_label = trans(_('Date of Birth:'), lang)
    181175            f_label = Paragraph(f_label, ENTRY1_STYLE)
    182176            date_of_birth = studentview.context.date_of_birth
     
    194188    return table
    195189
    196 def render_table_data(tableheader,tabledata):
     190def render_table_data(tableheader, tabledata, lang='en'):
    197191    """Render children table for an existing frame.
    198192    """
     
    202196    style = getSampleStyleSheet()
    203197    for element in tableheader:
    204         field = '<strong>%s</strong>' % formatted_text(element[0])
     198        field = '<strong>%s</strong>' % formatted_text(element[0], lang=lang)
    205199        field = Paragraph(field, style["Normal"])
    206200        line.append(field)
     
    217211    return table
    218212
    219 def render_transcript_data(view,tableheader,levels_data):
     213def render_transcript_data(view, tableheader, levels_data, lang='en'):
    220214    """Render children table for an existing frame.
    221215    """
     
    228222        headerline = []
    229223        tabledata = []
    230         subheader = 'Session %s, Level %s' % (
     224        subheader = '%s %s, %s %s' % (
     225            trans(_('Session'), lang),
    231226            view.session_dict[level_obj.level_session],
     227            trans(_('Level'), lang),
    232228            view.course_levels.getTerm(level_obj.level).title)
    233229        data.append(Paragraph(subheader, HEADING_STYLE))
     
    247243            element[2]*cm for element in tableheader], style=CONTENT_STYLE)
    248244        data.append(table)
     245        sgpa = '%s: %s' % (trans('Sessional GPA', lang), level['sgpa'])
     246        data.append(Paragraph(sgpa, style["Normal"]))
    249247    return data
    250248
     
    551549
    552550        # Student data
    553         data.append(render_student_data(view, omit_fields))
     551        data.append(render_student_data(view, omit_fields, lang=portal_language))
    554552
    555553        # Insert history
     
    589587        """Render pdf slips for various pages.
    590588        """
     589        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    591590        # XXX: tell what the different parameters mean
    592591        style = getSampleStyleSheet()
     
    607606
    608607        # Insert student data table
    609         portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    610608        if student is not None:
    611609            bd_translation = trans(_('Base Data'), portal_language)
    612610            data.append(Paragraph(bd_translation, HEADING_STYLE))
    613             data.append(render_student_data(studentview, omit_fields))
     611            data.append(render_student_data(
     612                studentview, omit_fields, lang=portal_language))
    614613
    615614        # Insert widgets
    616615        if view.form_fields:
    617616            data.append(Paragraph(view.title, HEADING_STYLE))
    618             portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    619617            separators = getattr(self, 'SEPARATORS_DICT', {})
    620618            table = creator.getWidgetsTable(
     
    691689        """Render pdf slips for transcript.
    692690        """
     691        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    693692        # XXX: tell what the different parameters mean
    694693        style = getSampleStyleSheet()
     
    709708
    710709        # Insert student data table
    711         portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
    712710        if student is not None:
    713711            #bd_translation = trans(_('Base Data'), portal_language)
    714712            #data.append(Paragraph(bd_translation, HEADING_STYLE))
    715             data.append(render_student_data(studentview, omit_fields))
     713            data.append(render_student_data(
     714                studentview, omit_fields, lang=portal_language))
    716715
    717716
     
    721720
    722721        contextdata = []
    723         f_label = _('Course of Study:')
     722        f_label = trans(_('Course of Study:'), portal_language)
    724723        f_label = Paragraph(f_label, ENTRY1_STYLE)
    725724        f_text = formatted_text(view.context.certificate.longtitle())
     
    727726        contextdata.append([f_label,f_text])
    728727
    729         f_label = _('Faculty:')
     728        f_label = trans(_('Faculty:'), portal_language)
    730729        f_label = Paragraph(f_label, ENTRY1_STYLE)
    731730        f_text = formatted_text(
     
    734733        contextdata.append([f_label,f_text])
    735734
    736         f_label = _('Department:')
     735        f_label = trans(_('Department:'), portal_language)
    737736        f_label = Paragraph(f_label, ENTRY1_STYLE)
    738737        f_text = formatted_text(
     
    741740        contextdata.append([f_label,f_text])
    742741
    743         f_label = _('Entry Session:')
     742        f_label = trans(_('Entry Session:'), portal_language)
    744743        f_label = Paragraph(f_label, ENTRY1_STYLE)
    745744        f_text = formatted_text(
     
    748747        contextdata.append([f_label,f_text])
    749748
    750         f_label = _('Entry Mode:')
     749        f_label = trans(_('Entry Mode:'), portal_language)
    751750        f_label = Paragraph(f_label, ENTRY1_STYLE)
    752751        f_text = formatted_text(view.studymode_dict.get(
     
    755754        contextdata.append([f_label,f_text])
    756755
    757         f_label = _('Final GPA:')
     756        f_label = trans(_('Final GPA:'), portal_language)
    758757        f_label = Paragraph(f_label, ENTRY1_STYLE)
    759758        f_text = formatted_text(gpa)
     
    765764
    766765        transcripttables = render_transcript_data(
    767             view, tableheader, levels_data)
     766            view, tableheader, levels_data, lang=portal_language)
    768767        data.extend(transcripttables)
    769768
     
    786785                note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin)
    787786        except IOError:
    788             view.flash('Error in image file.')
     787            view.flash(_('Error in image file.'))
    789788            return view.redirect(view.url(view.context))
    790789        return pdf_stream
Note: See TracChangeset for help on using the changeset viewer.