Changeset 6358
- Timestamp:
- 12 Jun 2011, 11:55:41 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py
r6357 r6358 27 27 from datetime import datetime 28 28 from zope.formlib.widget import CustomWidgetFactory 29 from zope.formlib.form import setUpEditWidgets 29 30 from zope.securitypolicy.interfaces import IPrincipalRoleManager 30 31 from zope.traversing.browser import absoluteURL … … 516 517 return 'not yet admitted' 517 518 519 class PDFActionButton(ManageActionButton): 520 grok.context(IApplicant) 521 grok.view(DisplayApplicant) 522 grok.require('waeup.handleApplication') 523 icon = 'actionicon_pdf.png' 524 text = 'Download pdf slip' 525 target = 'application_slip.pdf' 526 527 class ExportPDFPage(grok.View): 528 """Deliver a PDF slip of the context. 529 """ 530 grok.context(IApplicant) 531 grok.name('application_slip.pdf') 532 grok.require('waeup.handleApplication') 533 form_fields = grok.AutoFields(IApplicant).omit( 534 'locked').omit('course_admitted') 535 form_fields['passport'].custom_widget = ThumbnailWidget 536 form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le') 537 538 prefix = 'form' 539 540 def getCourseAdmitted(self): 541 """Return title and code in html format to the certificate 542 admitted. 543 """ 544 course_admitted = self.context.course_admitted 545 if ICertificate.providedBy(course_admitted): 546 title = course_admitted.title 547 code = course_admitted.code 548 return '%s (%s)' %(title,code) 549 return 'not yet admitted' 550 551 def setUpWidgets(self, ignore_request=False): 552 self.adapters = {} 553 self.widgets = setUpEditWidgets( 554 self.form_fields, self.prefix, self.context, self.request, 555 adapters=self.adapters, for_display=True, 556 ignore_request=ignore_request 557 ) 558 559 # Render a demo pdf page 560 def render(self): 561 from reportlab.pdfgen import canvas 562 from reportlab.lib.units import cm 563 from reportlab.lib.pagesizes import A4, landscape 564 from reportlab.lib.styles import getSampleStyleSheet 565 from reportlab.platypus import Frame, Paragraph 566 567 pdf = canvas.Canvas('application_slip.pdf',pagesize=A4) 568 width, height = A4 569 style = getSampleStyleSheet() 570 story = [] 571 frame = Frame(1*cm,1*cm,width-(2*cm),height-(2*cm)) 572 self.setUpWidgets() 573 #import pdb; pdb.set_trace() 574 for widget in self.widgets: 575 if widget.name != 'form.passport': 576 ptext = widget() 577 story.append(Paragraph(ptext, style["Normal"])) 578 frame.addFromList(story,pdf) 579 self.response.setHeader( 580 'Content-Type', 'application/pdf') 581 return pdf.getpdfdata() 582 518 583 class ApplicantsManageActionButton(ManageActionButton): 519 584 grok.context(IApplicant) … … 574 639 return 575 640 576 class PDFActionButton(ManageActionButton):577 grok.context(IApplicant)578 grok.view(DisplayApplicant)579 grok.require('waeup.handleApplication')580 icon = 'actionicon_pdf.png'581 text = 'Download pdf slip'582 target = 'application_slip.pdf'583 584 class ExportPDFPage(grok.View):585 """Deliver a PDF slip of the context.586 """587 grok.context(IApplicant)588 grok.name('application_slip.pdf')589 grok.require('waeup.handleApplication')590 591 # Render a demo pdf pagge592 def render(self):593 #exporter = IWAeUPXMLExporter(self.context)594 #xml = exporter.export().read()595 pdf = canvas.Canvas("application_slip.pdf")596 pdf.drawString(100,750,"Welcome to Reportlab!")597 self.response.setHeader(598 'Content-Type', 'application/pdf')599 return pdf.getpdfdata()600 601 641 class EditApplicantStudent(EditApplicantFull): 602 642 """An applicant-centered edit view for applicant data.
Note: See TracChangeset for help on using the changeset viewer.