Changeset 16100 for main/waeup.uniben/trunk/src/waeup/uniben/students
- Timestamp:
- 25 May 2020, 12:11:26 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py
r16025 r16100 465 465 return None 466 466 467 def renderPDFTranscript(self, view, filename='transcript.pdf', 468 student=None, 469 studentview=None, 470 note=None, 471 signatures=(), 472 sigs_in_footer=(), 473 digital_sigs=(), 474 show_scans=True, topMargin=1.5, 475 omit_fields=(), 476 tableheader=None, 477 no_passport=False, 478 save_file=False): 479 """Render pdf slip of a transcripts. 480 """ 481 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 482 # XXX: tell what the different parameters mean 483 style = getSampleStyleSheet() 484 creator = self.getPDFCreator(student) 485 data = [] 486 doc_title = view.label 487 author = '%s (%s)' % (view.request.principal.title, 488 view.request.principal.id) 489 footer_text = view.label.split('\n') 490 if len(footer_text) > 2: 491 # We can add a department in first line 492 footer_text = footer_text[1] 493 else: 494 # Only the first line is used for the footer 495 footer_text = footer_text[0] 496 if getattr(student, 'student_id', None) is not None: 497 footer_text = "%s - %s - " % (student.student_id, footer_text) 498 499 # Insert student data table 500 if student is not None: 501 #bd_translation = trans(_('Base Data'), portal_language) 502 #data.append(Paragraph(bd_translation, HEADING_STYLE)) 503 data.append(render_student_data( 504 studentview, view.context, 505 omit_fields, lang=portal_language, 506 slipname=filename, 507 no_passport=no_passport)) 508 509 transcript_data = view.context.getTranscriptData() 510 levels_data = transcript_data[0] 511 512 contextdata = [] 513 f_label = trans(_('Course of Study:'), portal_language) 514 f_label = Paragraph(f_label, ENTRY1_STYLE) 515 f_text = formatted_text(view.context.certificate.longtitle) 516 f_text = Paragraph(f_text, ENTRY1_STYLE) 517 contextdata.append([f_label,f_text]) 518 519 f_label = trans(_('Faculty:'), portal_language) 520 f_label = Paragraph(f_label, ENTRY1_STYLE) 521 f_text = formatted_text( 522 view.context.certificate.__parent__.__parent__.__parent__.longtitle) 523 f_text = Paragraph(f_text, ENTRY1_STYLE) 524 contextdata.append([f_label,f_text]) 525 526 f_label = trans(_('Department:'), portal_language) 527 f_label = Paragraph(f_label, ENTRY1_STYLE) 528 f_text = formatted_text( 529 view.context.certificate.__parent__.__parent__.longtitle) 530 f_text = Paragraph(f_text, ENTRY1_STYLE) 531 contextdata.append([f_label,f_text]) 532 533 f_label = trans(_('Entry Session:'), portal_language) 534 f_label = Paragraph(f_label, ENTRY1_STYLE) 535 f_text = formatted_text( 536 view.session_dict.get(view.context.entry_session)) 537 f_text = Paragraph(f_text, ENTRY1_STYLE) 538 contextdata.append([f_label,f_text]) 539 540 f_label = trans(_('Final Session:'), portal_language) 541 f_label = Paragraph(f_label, ENTRY1_STYLE) 542 f_text = formatted_text( 543 view.session_dict.get(view.context.current_session)) 544 f_text = Paragraph(f_text, ENTRY1_STYLE) 545 contextdata.append([f_label,f_text]) 546 547 f_label = trans(_('Entry Mode:'), portal_language) 548 f_label = Paragraph(f_label, ENTRY1_STYLE) 549 f_text = formatted_text(view.studymode_dict.get( 550 view.context.entry_mode)) 551 f_text = Paragraph(f_text, ENTRY1_STYLE) 552 contextdata.append([f_label,f_text]) 553 554 f_label = trans(_('Final Verdict:'), portal_language) 555 f_label = Paragraph(f_label, ENTRY1_STYLE) 556 f_text = formatted_text(view.studymode_dict.get( 557 view.context.current_verdict)) 558 f_text = Paragraph(f_text, ENTRY1_STYLE) 559 contextdata.append([f_label,f_text]) 560 561 f_label = trans(_('Cumulative GPA:'), portal_language) 562 f_label = Paragraph(f_label, ENTRY1_STYLE) 563 format_float = getUtility(IKofaUtils).format_float 564 cgpa = format_float(transcript_data[1], 3) 565 if student.state == GRADUATED: 566 f_text = formatted_text('%s (%s)' % ( 567 cgpa, self.getClassFromCGPA(transcript_data[1], student)[1])) 568 else: 569 f_text = formatted_text('%s' % cgpa) 570 f_text = Paragraph(f_text, ENTRY1_STYLE) 571 contextdata.append([f_label,f_text]) 572 573 contexttable = Table(contextdata,style=SLIP_STYLE) 574 data.append(contexttable) 575 576 transcripttables = render_transcript_data( 577 view, tableheader, levels_data, lang=portal_language) 578 data.extend(transcripttables) 579 580 # Insert signatures 581 # XXX: We are using only sigs_in_footer in waeup.kofa, so we 582 # do not have a test for the following lines. 583 if signatures and not sigs_in_footer: 584 data.append(Spacer(1, 20)) 585 # Render one signature table per signature to 586 # get date and signature in line. 587 for signature in signatures: 588 signaturetables = get_signature_tables(signature) 589 data.append(signaturetables[0]) 590 591 # Insert digital signatures 592 if digital_sigs: 593 data.append(Spacer(1, 20)) 594 sigs = digital_sigs.split('\n') 595 for sig in sigs: 596 data.append(Paragraph(sig, NOTE_STYLE)) 597 598 view.response.setHeader( 599 'Content-Type', 'application/pdf') 600 try: 601 pdf_stream = creator.create_pdf( 602 data, None, doc_title, author=author, footer=footer_text, 603 note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin) 604 except IOError: 605 view.flash(_('Error in image file.')) 606 return view.redirect(view.url(view.context)) 607 if save_file: 608 self._saveTranscriptPDF(student, pdf_stream) 609 return 610 return pdf_stream 611 467 612 #: A tuple containing the names of registration states in which changing of 468 613 #: passport pictures is allowed.
Note: See TracChangeset for help on using the changeset viewer.