Changeset 7019 for main/waeup.sirp/trunk/src/waeup/sirp/students
- Timestamp:
- 7 Nov 2011, 13:03:42 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/students
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7017 r7019 52 52 from waeup.sirp.students.vocabularies import StudyLevelSource 53 53 from waeup.sirp.students.utils import ( 54 getPaymentDetails, getAccommodationDetails, selectBed )54 getPaymentDetails, getAccommodationDetails, selectBed, renderPDF) 55 55 from waeup.sirp.browser.resources import toggleall 56 56 from waeup.sirp.authentication import get_principal_role_manager … … 957 957 def label(self): 958 958 return '%s: Online Payment Ticket %s' % ( 959 self.context.__parent__.__parent__.fullname,self.context.p_id) 959 self.context.getStudent().fullname,self.context.p_id) 960 961 class PaymentReceiptActionButton(ManageActionButton): 962 grok.context(IStudentOnlinePayment) 963 grok.require('waeup.viewStudent') 964 icon = 'actionicon_pdf.png' 965 text = 'Download payment receipt' 966 target = 'payment_receipt.pdf' 960 967 961 968 class OnlinePaymentCallbackPage(grok.View): … … 1005 1012 return 1006 1013 1014 class ExportPDFPaymentSlipPage(grok.View): 1015 """Deliver a PDF slip of the context. 1016 """ 1017 grok.context(IStudentOnlinePayment) 1018 grok.name('payment_receipt.pdf') 1019 grok.require('waeup.viewStudent') 1020 form_fields = grok.AutoFields(IStudentOnlinePayment) 1021 form_fields['creation_date'].custom_widget = FriendlyDateDisplayWidget('le') 1022 form_fields['payment_date'].custom_widget = FriendlyDateDisplayWidget('le') 1023 prefix = 'form' 1024 1025 @property 1026 def label(self): 1027 return 'Online Payment Receipt %s' % self.context.p_id 1028 1029 def render(self): 1030 studentview = StudentBaseDisplayFormPage(self.context.getStudent(), 1031 self.request) 1032 return renderPDF(self,'Payment', 'payment_receipt.pdf', 1033 self.context.getStudent, studentview) 1034 1007 1035 # We don't need the display form page yet 1008 1036 #class AccommodationDisplayFormPage(WAeUPDisplayFormPage): -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r7018 r7019 696 696 self.assertMatches('...Amount Authorized...', 697 697 self.browser.contents) 698 698 payment_url = self.browser.url 699 699 # Managers can open the callback view which simulates a valid callback 700 700 self.assertEqual(len(self.app['accesscodes']['SFE-0']),0) 701 self.browser.open( self.browser.url + '/callback')701 self.browser.open(payment_url + '/callback') 702 702 self.assertMatches('...Valid callback received...', 703 703 self.browser.contents) 704 705 # Managers can open the pdf payment receipt 706 self.browser.open(payment_url + '/payment_receipt.pdf') 707 self.assertEqual(self.browser.headers['Status'], '200 Ok') 708 self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') 704 709 705 710 # Managers can remove online school fee payment tickets … … 769 774 value = ctrl.options[0] 770 775 self.browser.getLink(value).click() 771 self.browser.open(self.browser.url + '/callback') 776 payment_url = self.browser.url 777 self.browser.open(payment_url + '/callback') 772 778 self.assertMatches('...Valid callback received...', 773 779 self.browser.contents) … … 782 788 ac = self.app['accesscodes']['CLR-0'][pin] 783 789 ac.owner = self.student_id 790 791 # Students can open the pdf payment receipt 792 self.browser.open(payment_url + '/payment_receipt.pdf') 793 self.assertEqual(self.browser.headers['Status'], '200 Ok') 794 self.assertEqual(self.browser.headers['Content-Type'], 'application/pdf') 795 784 796 # The new CLR-0 pin can be used for starting clearance 785 797 IWorkflowInfo(self.student).fireTransition('admit') -
main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py
r7004 r7019 3 3 from grok import getSite 4 4 from random import SystemRandom as r 5 from datetime import date, datetime 6 from reportlab.pdfgen import canvas 7 from reportlab.lib.units import cm 8 from reportlab.lib.pagesizes import A4 9 from reportlab.lib.styles import getSampleStyleSheet 10 from reportlab.platypus import (Frame, Paragraph, Image, 11 Table, Spacer) 12 from reportlab.platypus.tables import TableStyle 13 from zope.formlib.form import setUpEditWidgets 5 14 from waeup.sirp.interfaces import academic_sessions_vocab 15 16 SLIP_STYLE = TableStyle( 17 [('VALIGN',(0,0),(-1,-1),'TOP')] 18 ) 6 19 7 20 def generate_student_id(students,letter): … … 85 98 def selectBed(available_beds): 86 99 return available_beds[0] 100 101 def setUpWidgets(view, ignore_request=False): 102 view.adapters = {} 103 view.widgets = setUpEditWidgets( 104 view.form_fields, view.prefix, view.context, view.request, 105 adapters=view.adapters, for_display=True, 106 ignore_request=ignore_request 107 ) 108 109 def renderStudentData(student, studentview): 110 setUpWidgets(studentview, ignore_request=True) 111 data = [] 112 style = getSampleStyleSheet() 113 for widget in studentview.widgets: 114 if widget.name == 'form.adm_code': 115 continue 116 f_label = '<font size=12>%s</font>:' % widget.label.strip() 117 f_label = Paragraph(f_label, style["Normal"]) 118 f_text = '<font size=12>%s</font>' % widget() 119 f_text = Paragraph(f_text, style["Normal"]) 120 data.append([f_label,f_text]) 121 table = Table(data,style=SLIP_STYLE) 122 return table 123 124 # To be specified in customization packages, see also view which 125 # calls the function. 126 def renderPDF(view, subject='', filename='slip.pdf', student=None, studentview=None): 127 # (0,0),(-1,-1) = whole table 128 # (0,0),(0,-1) = first column 129 # (-1,0),(-1,-1) = last column 130 # (0,0),(-1,0) = first row 131 # (0,-1),(-1,-1) = last row 132 133 pdf = canvas.Canvas(filename,pagesize=A4) 134 pdf.setTitle(view.label) 135 pdf.setSubject(subject) 136 pdf.setAuthor('%s (%s)' % (view.request.principal.title, 137 view.request.principal.id)) 138 pdf.setCreator('WAeUP SIRP') 139 width, height = A4 140 style = getSampleStyleSheet() 141 pdf.line(1*cm,height-(1.8*cm),width-(1*cm),height-(1.8*cm)) 142 143 story = [] 144 frame_header = Frame(1*cm,1*cm,width-(1.7*cm),height-(1.7*cm)) 145 header_title = getattr(getSite(), 'name', u'Sample University') 146 story.append(Paragraph(header_title, style["Heading1"])) 147 frame_header.addFromList(story,pdf) 148 149 story = [] 150 frame_body = Frame(1*cm,1*cm,width-(2*cm),height-(3.5*cm)) 151 story.append(Paragraph(view.label, style["Heading2"])) 152 #story.append(HRFlowable()) 153 if student: 154 story.append(Spacer(1, 18)) 155 studenttable = renderStudentData(student, studentview) 156 story.append(studenttable) 157 story.append(Spacer(1, 18)) 158 setUpWidgets(view) 159 data = [] 160 for widget in view.widgets: 161 f_label = '<font size=12>%s</font>:' % widget.label.strip() 162 f_label = Paragraph(f_label, style["Normal"]) 163 f_text = '<font size=12>%s</font>' % widget() 164 f_text = Paragraph(f_text, style["Normal"]) 165 data.append([f_label,f_text]) 166 table = Table(data,style=SLIP_STYLE) 167 story.append(table) 168 frame_body.addFromList(story,pdf) 169 170 story = [] 171 frame_footer = Frame(1*cm,0,width-(2*cm),1*cm) 172 timestamp = datetime.now().strftime("%d/%m/%Y %H:%M:%S") 173 f_text = '<font size=10>%s</font>' % timestamp 174 story.append(Paragraph(f_text, style["Normal"])) 175 frame_footer.addFromList(story,pdf) 176 177 view.response.setHeader( 178 'Content-Type', 'application/pdf') 179 return pdf.getpdfdata()
Note: See TracChangeset for help on using the changeset viewer.