Changeset 11911
- Timestamp:
- 29 Oct 2014, 16:44:30 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-stud-utils-cleanup/src/waeup/kofa/students/utils.py
r11875 r11911 36 36 from waeup.kofa.students.interfaces import IStudentsUtils 37 37 from waeup.kofa.students.workflow import ADMITTED 38 from waeup.kofa.students.vocabularies import StudyLevelSource, MatNumNotInSource 38 from waeup.kofa.students.vocabularies import ( 39 StudyLevelSource, MatNumNotInSource, 40 ) 39 41 from waeup.kofa.browser.pdf import ( 40 ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE, 42 ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE, 41 43 get_signature_tables, get_qrcode) 42 44 from waeup.kofa.browser.interfaces import IPDFCreator … … 44 46 45 47 SLIP_STYLE = [ 46 ('VALIGN', (0,0),(-1,-1),'TOP'),47 #('FONT', (0, 0), (-1,-1), 'Helvetica', 11),48 ('VALIGN', (0, 0), (-1, -1), 'TOP'), 49 #('FONT', (0, 0), (-1, -1), 'Helvetica', 11), 48 50 ] 49 51 50 52 CONTENT_STYLE = [ 51 ('VALIGN',(0,0),(-1,-1),'TOP'), 52 #('FONT', (0,0), (-1,-1), 'Helvetica', 8), 53 #('TEXTCOLOR',(0,0),(-1,0),colors.white), 54 #('BACKGROUND',(0,0),(-1,0),colors.black), 55 ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), 56 ('BOX', (0,0), (-1,-1), 1, colors.black), 57 53 ('VALIGN', (0, 0), (-1, -1), 'TOP'), 54 #('FONT', (0, 0), (-1, -1), 'Helvetica', 8), 55 #('TEXTCOLOR', (0, 0), (-1, 0), colors.white), 56 #('BACKGROUND', (0, 0),(-1, 0), colors.black), 57 ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black), 58 ('BOX', (0, 0), (-1, -1), 1, colors.black), 58 59 ] 59 60 60 61 FONT_SIZE = 10 61 62 FONT_COLOR = 'black' 63 62 64 63 65 def trans(text, lang): 64 66 # shortcut 65 67 return translate(text, 'waeup.kofa', target_language=lang) 68 66 69 67 70 def formatted_text(text, color=FONT_COLOR, lang='en'): … … 93 96 return tag1 + u'%s</font>' % text 94 97 98 95 99 def generate_student_id(): 96 100 students = grok.getSite()['students'] 97 101 new_id = students.unique_student_id 98 102 return new_id 103 99 104 100 105 def set_up_widgets(view, ignore_request=False): … … 105 110 ignore_request=ignore_request 106 111 ) 112 107 113 108 114 def render_student_data(studentview, context, omit_fields=(), … … 120 126 from waeup.kofa.browser import DEFAULT_PASSPORT_IMAGE_PATH 121 127 img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb') 122 doc_img = Image(img.name, width=4 *cm, height=4*cm, kind='bound')128 doc_img = Image(img.name, width=4 * cm, height=4 * cm, kind='bound') 123 129 data_left.append([doc_img]) 124 130 #data.append([Spacer(1, 12)]) … … 128 134 f_text = formatted_text(studentview.context.display_fullname) 129 135 f_text = Paragraph(f_text, ENTRY1_STYLE) 130 data_middle.append([f_label, f_text])136 data_middle.append([f_label, f_text]) 131 137 132 138 for widget in studentview.widgets: … … 139 145 f_text = formatted_text(widget(), lang=lang) 140 146 f_text = Paragraph(f_text, ENTRY1_STYLE) 141 data_middle.append([f_label, f_text])147 data_middle.append([f_label, f_text]) 142 148 143 149 if getattr(studentview.context, 'certcode', None): … … 148 154 studentview.context['studycourse'].certificate.longtitle) 149 155 f_text = Paragraph(f_text, ENTRY1_STYLE) 150 data_middle.append([f_label, f_text])156 data_middle.append([f_label, f_text]) 151 157 if not 'department' in omit_fields: 152 158 f_label = trans(_('Department:'), lang) … … 157 163 ) 158 164 f_text = Paragraph(f_text, ENTRY1_STYLE) 159 data_middle.append([f_label, f_text])165 data_middle.append([f_label, f_text]) 160 166 if not 'faculty' in omit_fields: 161 167 f_label = trans(_('Faculty:'), lang) 162 168 f_label = Paragraph(f_label, ENTRY1_STYLE) 163 f_text = formatted_text(164 studentview.context[165 'studycourse'].certificate.__parent__.__parent__.__parent__.longtitle,166 169 course = studentview.context['studycourse'] 170 cert = course.certificate 171 longtitle = cert.__parent__.__parent__.__parent__.longtitle 172 f_text = formatted_text(longtitle) 167 173 f_text = Paragraph(f_text, ENTRY1_STYLE) 168 data_middle.append([f_label, f_text])174 data_middle.append([f_label, f_text]) 169 175 if not 'current_mode' in omit_fields: 170 176 studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT … … 174 180 f_text = formatted_text(sm) 175 181 f_text = Paragraph(f_text, ENTRY1_STYLE) 176 data_middle.append([f_label, f_text])182 data_middle.append([f_label, f_text]) 177 183 if not 'entry_session' in omit_fields: 178 184 f_label = trans(_('Entry Session:'), lang) 179 185 f_label = Paragraph(f_label, ENTRY1_STYLE) 180 186 entry_session = studentview.context.entry_session 181 entry_session = academic_sessions_vocab.getTerm(entry_session).title 187 entry_session = academic_sessions_vocab.getTerm( 188 entry_session).title 182 189 f_text = formatted_text(entry_session) 183 190 f_text = Paragraph(f_text, ENTRY1_STYLE) 184 data_middle.append([f_label, f_text])191 data_middle.append([f_label, f_text]) 185 192 # Requested by Uniben, does not really make sense 186 193 if not 'current_level' in omit_fields: … … 193 200 f_text = formatted_text(current_level) 194 201 f_text = Paragraph(f_text, ENTRY1_STYLE) 195 data_middle.append([f_label, f_text])202 data_middle.append([f_label, f_text]) 196 203 if not 'date_of_birth' in omit_fields: 197 204 f_label = trans(_('Date of Birth:'), lang) … … 204 211 f_text = formatted_text(date_of_birth) 205 212 f_text = Paragraph(f_text, ENTRY1_STYLE) 206 data_middle.append([f_label, f_text])213 data_middle.append([f_label, f_text]) 207 214 208 215 # append QR code to the right … … 210 217 url = studentview.url(context, slipname) 211 218 data_right = [[get_qrcode(url, width=70.0)]] 212 table_right = Table(data_right, style=SLIP_STYLE)219 table_right = Table(data_right, style=SLIP_STYLE) 213 220 else: 214 221 table_right = None 215 222 216 table_left = Table(data_left,style=SLIP_STYLE) 217 table_middle = Table(data_middle,style=SLIP_STYLE, colWidths=[5*cm, 5*cm]) 218 table = Table([[table_left, table_middle, table_right],],style=SLIP_STYLE) 223 table_left = Table(data_left, style=SLIP_STYLE) 224 table_middle = Table(data_middle, style=SLIP_STYLE, 225 colWidths=[5 * cm, 5 * cm]) 226 table = Table([[table_left, table_middle, table_right], ], 227 style=SLIP_STYLE) 219 228 return table 229 220 230 221 231 def render_table_data(tableheader, tabledata, lang='en'): … … 234 244 line = [] 235 245 for element in tableheader: 236 field = formatted_text(getattr(ticket,element[1],u' '))237 238 246 field = formatted_text(getattr(ticket, element[1], u' ')) 247 field = Paragraph(field, style["Normal"]) 248 line.append(field) 239 249 data.append(line) 240 table = Table(data, colWidths=[241 element[2] *cm for element in tableheader], style=CONTENT_STYLE)250 table = Table(data, colWidths=[ 251 element[2] * cm for element in tableheader], style=CONTENT_STYLE) 242 252 return table 253 243 254 244 255 def render_transcript_data(view, tableheader, levels_data, lang='en'): … … 266 277 ticketline = [] 267 278 for element in tableheader: 268 field = formatted_text(getattr(ticket,element[1],u' '))269 270 279 field = formatted_text(getattr(ticket, element[1], u' ')) 280 field = Paragraph(field, style["Normal"]) 281 ticketline.append(field) 271 282 tabledata.append(ticketline) 272 table = Table(tabledata, colWidths=[273 element[2] *cm for element in tableheader], style=CONTENT_STYLE)283 table = Table(tabledata, colWidths=[ 284 element[2] * cm for element in tableheader], style=CONTENT_STYLE) 274 285 data.append(table) 275 sgpa = '%s: %s' % (trans('Sessional GPA (rectified)', lang), level['sgpa']) 286 sgpa = '%s: %s' % ( 287 trans('Sessional GPA (rectified)', lang), level['sgpa']) 276 288 data.append(Paragraph(sgpa, style["Normal"])) 277 289 return data 290 278 291 279 292 def docs_as_flowables(view, lang='en'): … … 300 313 img_path = getattr(getUtility(IExtFileStore).getFileByContext( 301 314 view.context, attr=viewlet.download_name), 'name', None) 302 #f_text = Paragraph(trans(_('(not provided)'),lang), ENTRY1_STYLE)303 315 if img_path is None: 304 316 pass … … 308 320 viewlet.title,), ENTRY1_STYLE) 309 321 else: 310 f_text = Image(img_path, width=2*cm, height=1*cm, kind='bound') 322 f_text = Image( 323 img_path, width=2 * cm, height=1 * cm, kind='bound') 311 324 table_data.append([f_label, f_text]) 312 325 if table_data: … … 314 327 data.append(Table(table_data, style=SLIP_STYLE)) 315 328 return data 329 316 330 317 331 class StudentsUtils(grok.GlobalUtility): … … 367 381 for key in student['payments'].keys(): 368 382 ticket = student['payments'][key] 369 if ticket.p_state == 'paid' and\370 ticket.p_category == category and \371 ticket.p_item == p_item and \372 ticket.p_session == p_session:373 383 if (ticket.p_state == 'paid') and ( 384 ticket.p_category == category) and ( 385 ticket.p_item == p_item) and ( 386 ticket.p_session == p_session): 387 return True 374 388 return False 375 389 … … 391 405 return _('This is not a previous session.'), None 392 406 else: 393 if previous_session > student['studycourse'].current_session - 1: 407 if previous_session > ( 408 student['studycourse'].current_session - 1): 394 409 return _('This is not a previous session.'), None 395 410 p_session = previous_session … … 478 493 return _('Payment temporarily disabled.'), None 479 494 payment = createObject(u'waeup.StudentOnlinePayment') 480 timestamp = ("%d" % int(time() *10000))[1:]495 timestamp = ("%d" % int(time() * 10000))[1:] 481 496 payment.p_id = "p%s" % timestamp 482 497 payment.p_category = category … … 506 521 return _('This type of payment has already been made.'), None 507 522 payment = createObject(u'waeup.StudentOnlinePayment') 508 timestamp = ("%d" % int(time() *10000))[1:]523 timestamp = ("%d" % int(time() * 10000))[1:] 509 524 payment.p_id = "p%s" % timestamp 510 525 payment.p_category = category … … 568 583 # Determine bed type 569 584 studycourse = student['studycourse'] 570 certificate = getattr(studycourse, 'certificate',None)585 certificate = getattr(studycourse, 'certificate', None) 571 586 entry_session = studycourse.entry_session 572 587 current_level = studycourse.current_level … … 587 602 sex = 'male' 588 603 special_handling = 'regular' 589 d['bt'] = u'%s_%s_%s' % (special_handling, sex,bt)604 d['bt'] = u'%s_%s_%s' % (special_handling, sex, bt) 590 605 return d 591 606 … … 602 617 text = trans(_( 603 618 'This is to inform you that you have been provisionally' 604 ' admitted into ${a} as follows:', mapping ={'a': inst_name}),619 ' admitted into ${a} as follows:', mapping={'a': inst_name}), 605 620 portal_language) 606 621 return text … … 647 662 if post_text is None: 648 663 datelist = student.history.messages[0].split()[0].split('-') 649 creation_date = u'%s/%s/%s' % (datelist[2], datelist[1], datelist[0]) 664 creation_date = u'%s/%s/%s' % ( 665 datelist[2], datelist[1], datelist[0]) 650 666 post_text = trans(_( 651 667 'Your Kofa student record was created on ${a}.', 652 mapping ={'a': creation_date}),668 mapping={'a': creation_date}), 653 669 portal_language) 654 670 #html = format_html(post_text) … … 731 747 data.append(Paragraph(view.tabletitle[i], HEADING_STYLE)) 732 748 data.append(Spacer(1, 8)) 733 contenttable = render_table_data(tableheader[i],tabledata[i]) 749 contenttable = render_table_data( 750 tableheader[i], tabledata[i]) 734 751 data.append(contenttable) 735 752 … … 823 840 f_text = formatted_text(view.context.certificate.longtitle) 824 841 f_text = Paragraph(f_text, ENTRY1_STYLE) 825 contextdata.append([f_label, f_text])842 contextdata.append([f_label, f_text]) 826 843 827 844 f_label = trans(_('Faculty:'), portal_language) 828 845 f_label = Paragraph(f_label, ENTRY1_STYLE) 846 cert = view.context.certificate 829 847 f_text = formatted_text( 830 view.context.certificate.__parent__.__parent__.__parent__.longtitle)848 cert.__parent__.__parent__.__parent__.longtitle) 831 849 f_text = Paragraph(f_text, ENTRY1_STYLE) 832 contextdata.append([f_label, f_text])850 contextdata.append([f_label, f_text]) 833 851 834 852 f_label = trans(_('Department:'), portal_language) … … 837 855 view.context.certificate.__parent__.__parent__.longtitle) 838 856 f_text = Paragraph(f_text, ENTRY1_STYLE) 839 contextdata.append([f_label, f_text])857 contextdata.append([f_label, f_text]) 840 858 841 859 f_label = trans(_('Entry Session:'), portal_language) … … 844 862 view.session_dict.get(view.context.entry_session)) 845 863 f_text = Paragraph(f_text, ENTRY1_STYLE) 846 contextdata.append([f_label, f_text])864 contextdata.append([f_label, f_text]) 847 865 848 866 f_label = trans(_('Entry Mode:'), portal_language) … … 851 869 view.context.entry_mode)) 852 870 f_text = Paragraph(f_text, ENTRY1_STYLE) 853 contextdata.append([f_label, f_text])871 contextdata.append([f_label, f_text]) 854 872 855 873 f_label = trans(_('Cumulative GPA:'), portal_language) 856 874 f_label = Paragraph(f_label, ENTRY1_STYLE) 857 f_text = formatted_text('%s (%s)' % (gpa, self.getClassFromCGPA(gpa)[1])) 875 f_text = formatted_text('%s (%s)' % ( 876 gpa, self.getClassFromCGPA(gpa)[1])) 858 877 f_text = Paragraph(f_text, ENTRY1_STYLE) 859 contextdata.append([f_label, f_text])860 861 contexttable = Table(contextdata, style=SLIP_STYLE)878 contextdata.append([f_label, f_text]) 879 880 contexttable = Table(contextdata, style=SLIP_STYLE) 862 881 data.append(contexttable) 863 882
Note: See TracChangeset for help on using the changeset viewer.