Changeset 10261
- Timestamp:
- 31 May 2013, 06:38:59 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
r10256 r10261 62 62 return translate(text, 'waeup.kofa', target_language=lang) 63 63 64 def formatted_text(text, color=FONT_COLOR ):64 def formatted_text(text, color=FONT_COLOR, lang='en'): 65 65 """Turn `text`, `color` and `size` into an HTML snippet. 66 66 … … 76 76 The returned snippet is unicode type. 77 77 """ 78 try:79 # In unit tests IKofaUtils has not been registered80 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE81 except:82 portal_language = 'en'83 78 if not isinstance(text, unicode): 84 79 if isinstance(text, basestring): … … 90 85 # Mainly for boolean values we need our customized 91 86 # localisation of the zope domain 92 text = translate(text, 'zope', target_language= portal_language)87 text = translate(text, 'zope', target_language=lang) 93 88 text = text.replace('</div>', '<br /></div>') 94 89 tag1 = u'<font color="%s">' % (color) … … 108 103 ) 109 104 110 def render_student_data(studentview, omit_fields=() ):105 def render_student_data(studentview, omit_fields=(), lang='en'): 111 106 """Render student table for an existing frame. 112 107 """ … … 124 119 data_left.append([doc_img]) 125 120 #data.append([Spacer(1, 12)]) 126 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 127 128 f_label = _('Name:') 121 122 f_label = trans(_('Name:'), lang) 129 123 f_label = Paragraph(f_label, ENTRY1_STYLE) 130 124 f_text = formatted_text(studentview.context.display_fullname) … … 137 131 f_label = translate( 138 132 widget.label.strip(), 'waeup.kofa', 139 target_language= portal_language)133 target_language=lang) 140 134 f_label = Paragraph('%s:' % f_label, ENTRY1_STYLE) 141 f_text = formatted_text(widget() )135 f_text = formatted_text(widget(), lang=lang) 142 136 f_text = Paragraph(f_text, ENTRY1_STYLE) 143 137 data_right.append([f_label,f_text]) … … 145 139 if getattr(studentview.context, 'certcode', None): 146 140 if not 'certificate' in omit_fields: 147 f_label = _('Study Course:')141 f_label = trans(_('Study Course:'), lang) 148 142 f_label = Paragraph(f_label, ENTRY1_STYLE) 149 143 f_text = formatted_text( … … 152 146 data_right.append([f_label,f_text]) 153 147 if not 'department' in omit_fields: 154 f_label = _('Department:')148 f_label = trans(_('Department:'), lang) 155 149 f_label = Paragraph(f_label, ENTRY1_STYLE) 156 150 f_text = formatted_text( … … 161 155 data_right.append([f_label,f_text]) 162 156 if not 'faculty' in omit_fields: 163 f_label = _('Faculty:')157 f_label = trans(_('Faculty:'), lang) 164 158 f_label = Paragraph(f_label, ENTRY1_STYLE) 165 159 f_text = formatted_text( … … 170 164 data_right.append([f_label,f_text]) 171 165 if not 'entry_session' in omit_fields: 172 f_label = _('Entry Session: ')166 f_label = trans(_('Entry Session:'), lang) 173 167 f_label = Paragraph(f_label, ENTRY1_STYLE) 174 168 entry_session = studentview.context['studycourse'].entry_session … … 178 172 data_right.append([f_label,f_text]) 179 173 if not 'date_of_birth' in omit_fields: 180 f_label = _('Date of Birth: ')174 f_label = trans(_('Date of Birth:'), lang) 181 175 f_label = Paragraph(f_label, ENTRY1_STYLE) 182 176 date_of_birth = studentview.context.date_of_birth … … 194 188 return table 195 189 196 def render_table_data(tableheader, tabledata):190 def render_table_data(tableheader, tabledata, lang='en'): 197 191 """Render children table for an existing frame. 198 192 """ … … 202 196 style = getSampleStyleSheet() 203 197 for element in tableheader: 204 field = '<strong>%s</strong>' % formatted_text(element[0] )198 field = '<strong>%s</strong>' % formatted_text(element[0], lang=lang) 205 199 field = Paragraph(field, style["Normal"]) 206 200 line.append(field) … … 217 211 return table 218 212 219 def render_transcript_data(view, tableheader,levels_data):213 def render_transcript_data(view, tableheader, levels_data, lang='en'): 220 214 """Render children table for an existing frame. 221 215 """ … … 228 222 headerline = [] 229 223 tabledata = [] 230 subheader = 'Session %s, Level %s' % ( 224 subheader = '%s %s, %s %s' % ( 225 trans(_('Session'), lang), 231 226 view.session_dict[level_obj.level_session], 227 trans(_('Level'), lang), 232 228 view.course_levels.getTerm(level_obj.level).title) 233 229 data.append(Paragraph(subheader, HEADING_STYLE)) … … 247 243 element[2]*cm for element in tableheader], style=CONTENT_STYLE) 248 244 data.append(table) 245 sgpa = '%s: %s' % (trans('Sessional GPA', lang), level['sgpa']) 246 data.append(Paragraph(sgpa, style["Normal"])) 249 247 return data 250 248 … … 551 549 552 550 # Student data 553 data.append(render_student_data(view, omit_fields ))551 data.append(render_student_data(view, omit_fields, lang=portal_language)) 554 552 555 553 # Insert history … … 589 587 """Render pdf slips for various pages. 590 588 """ 589 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 591 590 # XXX: tell what the different parameters mean 592 591 style = getSampleStyleSheet() … … 607 606 608 607 # Insert student data table 609 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE610 608 if student is not None: 611 609 bd_translation = trans(_('Base Data'), portal_language) 612 610 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)) 614 613 615 614 # Insert widgets 616 615 if view.form_fields: 617 616 data.append(Paragraph(view.title, HEADING_STYLE)) 618 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE619 617 separators = getattr(self, 'SEPARATORS_DICT', {}) 620 618 table = creator.getWidgetsTable( … … 691 689 """Render pdf slips for transcript. 692 690 """ 691 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 693 692 # XXX: tell what the different parameters mean 694 693 style = getSampleStyleSheet() … … 709 708 710 709 # Insert student data table 711 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE712 710 if student is not None: 713 711 #bd_translation = trans(_('Base Data'), portal_language) 714 712 #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)) 716 715 717 716 … … 721 720 722 721 contextdata = [] 723 f_label = _('Course of Study:')722 f_label = trans(_('Course of Study:'), portal_language) 724 723 f_label = Paragraph(f_label, ENTRY1_STYLE) 725 724 f_text = formatted_text(view.context.certificate.longtitle()) … … 727 726 contextdata.append([f_label,f_text]) 728 727 729 f_label = _('Faculty:')728 f_label = trans(_('Faculty:'), portal_language) 730 729 f_label = Paragraph(f_label, ENTRY1_STYLE) 731 730 f_text = formatted_text( … … 734 733 contextdata.append([f_label,f_text]) 735 734 736 f_label = _('Department:')735 f_label = trans(_('Department:'), portal_language) 737 736 f_label = Paragraph(f_label, ENTRY1_STYLE) 738 737 f_text = formatted_text( … … 741 740 contextdata.append([f_label,f_text]) 742 741 743 f_label = _('Entry Session:')742 f_label = trans(_('Entry Session:'), portal_language) 744 743 f_label = Paragraph(f_label, ENTRY1_STYLE) 745 744 f_text = formatted_text( … … 748 747 contextdata.append([f_label,f_text]) 749 748 750 f_label = _('Entry Mode:')749 f_label = trans(_('Entry Mode:'), portal_language) 751 750 f_label = Paragraph(f_label, ENTRY1_STYLE) 752 751 f_text = formatted_text(view.studymode_dict.get( … … 755 754 contextdata.append([f_label,f_text]) 756 755 757 f_label = _('Final GPA:')756 f_label = trans(_('Final GPA:'), portal_language) 758 757 f_label = Paragraph(f_label, ENTRY1_STYLE) 759 758 f_text = formatted_text(gpa) … … 765 764 766 765 transcripttables = render_transcript_data( 767 view, tableheader, levels_data )766 view, tableheader, levels_data, lang=portal_language) 768 767 data.extend(transcripttables) 769 768 … … 786 785 note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin) 787 786 except IOError: 788 view.flash( 'Error in image file.')787 view.flash(_('Error in image file.')) 789 788 return view.redirect(view.url(view.context)) 790 789 return pdf_stream
Note: See TracChangeset for help on using the changeset viewer.