Changeset 7318
- Timestamp:
- 9 Dec 2011, 12:34:30 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py
r7276 r7318 623 623 form_fields['payment_date'].custom_widget = FriendlyDateDisplayWidget('le') 624 624 prefix = 'form' 625 title = 'Payment Data' 625 626 626 627 @property … … 636 637 self.request) 637 638 students_utils = getUtility(IStudentsUtils) 638 return students_utils.renderPDF(self,' Payment', 'payment_receipt.pdf',639 return students_utils.renderPDF(self,'payment_receipt.pdf', 639 640 self.context.__parent__, applicantview) 640 641 -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7310 r7318 90 90 """ 91 91 grok.context(IStudentsContainer) 92 title = u'Students'92 title = 'Students' 93 93 94 94 class StudentBreadcrumb(Breadcrumb): … … 104 104 """ 105 105 grok.context(IStudentStudyCourse) 106 title = u'Study Course'106 title = 'Study Course' 107 107 108 108 class PaymentsBreadcrumb(Breadcrumb): … … 110 110 """ 111 111 grok.context(IStudentPaymentsContainer) 112 title = u'Payments'112 title = 'Payments' 113 113 114 114 class OnlinePaymentBreadcrumb(Breadcrumb): … … 125 125 """ 126 126 grok.context(IStudentAccommodation) 127 title = u'Accommodation'127 title = 'Accommodation' 128 128 129 129 #@property … … 536 536 grok.require('waeup.viewStudent') 537 537 form_fields = grok.AutoFields(IStudentClearance).omit('clearance_locked') 538 form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le') 538 539 prefix = 'form' 540 title = 'Clearance Data' 539 541 540 542 @property … … 547 549 students_utils = getUtility(IStudentsUtils) 548 550 return students_utils.renderPDF( 549 self, 'Clearance','clearance.pdf',551 self, 'clearance.pdf', 550 552 self.context.getStudent(), studentview) 551 553 … … 819 821 form_fields = grok.AutoFields(IStudentStudyLevel) 820 822 prefix = 'form' 823 title = 'Level Data' 824 content_title = 'Course List' 821 825 822 826 @property … … 828 832 self.request) 829 833 students_utils = getUtility(IStudentsUtils) 834 tabledata = sorted(self.context.values(), 835 key=lambda value: str(value.semester) + value.code) 830 836 return students_utils.renderPDF( 831 self, 'Course Registration','course_registration.pdf',837 self, 'course_registration.pdf', 832 838 self.context.getStudent(), studentview, 833 839 tableheader=[('Sem.','semester', 1.5),('Code','code', 2.5), … … 838 844 ('Score', 'score', 1.5),('Auto', 'automatic', 1.5) 839 845 ], 840 tabledata= self.context.values())846 tabledata=tabledata) 841 847 842 848 class StudyLevelManageActionButton(ManageActionButton): … … 1255 1261 form_fields['payment_date'].custom_widget = FriendlyDateDisplayWidget('le') 1256 1262 prefix = 'form' 1263 title = 'Payment Data' 1257 1264 1258 1265 @property … … 1268 1275 self.request) 1269 1276 students_utils = getUtility(IStudentsUtils) 1270 return students_utils.renderPDF(self, 'Payment','payment_receipt.pdf',1277 return students_utils.renderPDF(self, 'payment_receipt.pdf', 1271 1278 self.context.getStudent(), studentview) 1272 1279 … … 1479 1486 form_fields['booking_date'].custom_widget = FriendlyDateDisplayWidget('le') 1480 1487 prefix = 'form' 1488 title = 'Bed Allocation Data' 1481 1489 1482 1490 @property 1483 1491 def label(self): 1484 return 'Bed Allocation %s' % self.context.bed_coordinates1492 return 'Bed Allocation: %s' % self.context.bed_coordinates 1485 1493 1486 1494 def render(self): … … 1489 1497 students_utils = getUtility(IStudentsUtils) 1490 1498 return students_utils.renderPDF( 1491 self, 'Bed Allocation','bed_allocation.pdf',1499 self, 'bed_allocation.pdf', 1492 1500 self.context.getStudent(), studentview) 1493 1501 -
main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py
r7310 r7318 22 22 from datetime import datetime 23 23 from reportlab.pdfgen import canvas 24 from reportlab.lib import colors 24 25 from reportlab.lib.units import cm 25 26 from reportlab.lib.enums import TA_RIGHT … … 35 36 from waeup.sirp.students.interfaces import IStudentsUtils 36 37 37 SLIP_STYLE = TableStyle( 38 [('VALIGN',(0,0),(-1,-1),'TOP')] 39 ) 40 41 CONTENT_STYLE = TableStyle( 42 [('VALIGN',(0,0),(-1,-1),'TOP')] 43 ) 38 SLIP_STYLE = [ 39 ('VALIGN',(0,0),(-1,-1),'TOP'), 40 #('FONT', (0,0), (-1,-1), 'Helvetica', 11), 41 ] 42 43 CONTENT_STYLE = [ 44 ('VALIGN',(0,0),(-1,-1),'TOP'), 45 #('FONT', (0,0), (-1,-1), 'Helvetica', 8), 46 #('TEXTCOLOR',(0,0),(-1,0),colors.white), 47 ('BACKGROUND',(0,0),(-1,0),colors.black), 48 ] 49 50 FONT_SIZE = 10 51 FONT_COLOR = 'black' 52 53 def formatted_string(color=FONT_COLOR, size=FONT_SIZE): 54 tag1 ='<font color=%s size=%d>' % (color, size) 55 return tag1 + '%s</font>' 44 56 45 57 def generate_student_id(students,letter): … … 68 80 69 81 def render_student_data(studentview): 82 """Render student table for an existing frame. 83 """ 84 width, height = A4 70 85 set_up_widgets(studentview, ignore_request=True) 71 data = [] 86 data_left = [] 87 data_right = [] 72 88 style = getSampleStyleSheet() 73 89 img = getUtility(IExtFileStore).getFileByContext( … … 76 92 from waeup.sirp.browser import DEFAULT_PASSPORT_IMAGE_PATH 77 93 img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb') 78 doc_img = Image(img.name, width=4*cm, height= 3*cm, kind='bound')79 data .append([doc_img])80 data.append([Spacer(1, 12)])94 doc_img = Image(img.name, width=4*cm, height=4*cm, kind='bound') 95 data_left.append([doc_img]) 96 #data.append([Spacer(1, 12)]) 81 97 for widget in studentview.widgets: 82 98 if widget.name == 'form.adm_code': 83 99 continue 84 f_label = '<font size=12>%s</font>:' % ( 85 widget.label.strip()) 100 f_label = formatted_string() % widget.label.strip() 86 101 f_label = Paragraph(f_label, style["Normal"]) 87 f_text = '<font size=12>%s</font>'% widget()102 f_text = formatted_string() % widget() 88 103 f_text = Paragraph(f_text, style["Normal"]) 89 data.append([f_label,f_text]) 90 table = Table(data,style=SLIP_STYLE) 104 data_right.append([f_label,f_text]) 105 table_left = Table(data_left,style=SLIP_STYLE) 106 table_right = Table(data_right,style=SLIP_STYLE, colWidths=[4*cm, 10*cm]) 107 table = Table([[table_left, table_right],],style=SLIP_STYLE) 91 108 return table 92 109 93 def insert_footer(pdf,width,style,text=None): 110 def render_table_data(tableheader,tabledata): 111 """Render children table for an existing frame. 112 """ 113 data = [] 114 #data.append([Spacer(1, 12)]) 115 line = [] 116 style = getSampleStyleSheet() 117 for element in tableheader: 118 field = formatted_string(color='white') % element[0] 119 field = Paragraph(field, style["Normal"]) 120 line.append(field) 121 data.append(line) 122 for ticket in tabledata: 123 line = [] 124 for element in tableheader: 125 field = formatted_string() % str(getattr(ticket,element[1],u' ')) 126 field = Paragraph(field, style["Normal"]) 127 line.append(field) 128 data.append(line) 129 table = Table(data,colWidths=[ 130 element[2]*cm for element in tableheader], style=CONTENT_STYLE) 131 return table 132 133 134 def insert_footer(pdf,width,style,text=None, number_of_pages=1): 135 """Render the whole footer frame. 136 """ 94 137 story = [] 95 138 frame_footer = Frame(1*cm,0,width-(2*cm),1*cm) … … 100 143 story = [] 101 144 frame_footer = Frame(1*cm,0,width-(2*cm),1*cm) 102 right_text = '<font size=10>%s Page %s </font>' % (103 text, pdf.getPageNumber() )145 right_text = '<font size=10>%s Page %s of %s</font>' % ( 146 text, pdf.getPageNumber(), number_of_pages) 104 147 story.append(Paragraph(right_text, style["Right"])) 105 148 frame_footer.addFromList(story,pdf) 106 107 def render_table_data(tableheader,tabledata):108 data = []109 data.append([Spacer(1, 12)])110 line = []111 style = getSampleStyleSheet()112 for element in tableheader:113 field = '<strong><font size=10>%s</font></strong>' % element[0]114 field = Paragraph(field, style["Normal"])115 line.append(field)116 data.append(line)117 for ticket in tabledata:118 line = []119 for element in tableheader:120 fieldcontent = getattr(ticket,element[1],u' ')121 field = '<font size=10>%s</font>' % fieldcontent122 field = Paragraph(field, style["BodyText"])123 line.append(field)124 data.append(line)125 # ToDo: The table does not show up if there are too many line126 # and it thus doesn't fit on the page127 table = Table(data,colWidths=[128 element[2]*cm for element in tableheader],style=CONTENT_STYLE)129 return table130 149 131 150 class StudentsUtils(grok.GlobalUtility): … … 190 209 return available_beds[0] 191 210 192 def renderPDF(self, view, subject='',filename='slip.pdf',211 def renderPDF(self, view, filename='slip.pdf', 193 212 student=None, studentview=None, tableheader=None, tabledata=None): 194 213 # (0,0),(-1,-1) = whole table … … 200 219 pdf = canvas.Canvas(filename,pagesize=A4) 201 220 pdf.setTitle(view.label) 202 pdf.setSubject( subject)221 pdf.setSubject(view.title) 203 222 pdf.setAuthor('%s (%s)' % (view.request.principal.title, 204 223 view.request.principal.id)) … … 218 237 frame_header.addFromList(story,pdf) 219 238 239 # Insert student data table 220 240 story = [] 221 241 frame_body = Frame(1*cm,1*cm,width-(2*cm),height-(3.5*cm)) 222 242 story.append(Paragraph(view.label, style["Heading2"])) 223 224 # Insert student data table225 243 if student is not None: 226 story.append(Spacer(1, 12)) 244 #story.append(Spacer(1, 12)) 245 story.append(Paragraph('Student Base Data', style["Heading3"])) 227 246 studenttable = render_student_data(studentview) 228 247 story.append(studenttable) 229 248 230 story.append(Spacer(1, 12))231 #story.append(PageBreak())249 # Insert widgets 250 story.append(Paragraph(view.title, style["Heading3"])) 232 251 set_up_widgets(view) 233 252 data = [] 234 253 for widget in view.widgets: 235 f_label = '<font size=12>%s</font>:'% widget.label.strip()254 f_label = formatted_string() % widget.label.strip() 236 255 f_label = Paragraph(f_label, style["Normal"]) 237 f_text = '<font size=12>%s</font>' % widget()256 f_text = formatted_string() % str(widget()) 238 257 f_text = Paragraph(f_text, style["Normal"]) 239 258 data.append([f_label,f_text]) 240 # First, import browser components locally 259 table = Table(data,style=SLIP_STYLE, colWidths=[5*cm, 13.5*cm]) 260 story.append(table) 261 262 # Import browser components locally 241 263 # to avoid circular import 242 264 from waeup.sirp.students.viewlets import FileManager 243 265 from waeup.sirp.browser import DEFAULT_IMAGE_PATH 266 data = [] 267 # Collect viewlets 244 268 fm = FileManager(view.context, view.request, view) 245 # Collect viewlets246 269 fm.update() 247 # Insert list of scanned documents 248 for viewlet in fm.viewlets: 249 f_label = '<font size=12>%s</font>' % viewlet.label 250 f_label = Paragraph(f_label, style["Normal"]) 251 if viewlet.template.__grok_name__ == 'imagedisplay': 252 # In case we define FileDisplay viewlets with 253 # an imagedisplay template in the customization package 254 img = getUtility(IExtFileStore).getFileByContext( 255 view.context, attr=viewlet.download_name) 256 if img is None: 257 img = open(DEFAULT_IMAGE_PATH, 'rb') 258 doc_img = Image(img.name, width=2*cm, height=1*cm, kind='bound') 259 data.append([f_label,doc_img]) 260 else: 261 f_text = '<font size=12>%s</font>' % viewlet.title 262 f_text = Paragraph(f_text, style["Normal"]) 263 data.append([f_label,f_text]) 264 table = Table(data,style=SLIP_STYLE) 265 story.append(table) 270 if fm.viewlets: 271 story.append(Paragraph('Scanned Documents', style["Heading3"])) 272 # Insert list of scanned documents 273 for viewlet in fm.viewlets: 274 f_label = formatted_string() % viewlet.label 275 f_label = Paragraph(f_label, style["Normal"]) 276 if viewlet.template.__grok_name__ == 'imagedisplay': 277 # In case we define FileDisplay viewlets with 278 # an imagedisplay template in the customization package 279 img = getUtility(IExtFileStore).getFileByContext( 280 view.context, attr=viewlet.download_name) 281 if img is None: 282 img = open(DEFAULT_IMAGE_PATH, 'rb') 283 doc_img = Image(img.name, width=2*cm, height=1*cm, kind='bound') 284 data.append([f_label,doc_img]) 285 else: 286 f_text = formatted_string() % viewlet.title 287 f_text = Paragraph(f_text, style["Normal"]) 288 data.append([f_label,f_text]) 289 table = Table(data,style=SLIP_STYLE, colWidths=[5*cm, 13.5*cm]) 290 story.append(table) 291 266 292 try: 267 293 frame_body.addFromList(story,pdf) … … 269 295 view.flash('Error in image file.') 270 296 return view.redirect(view.url(view.context)) 271 insert_footer(pdf,width,style,footer_text) 272 pdf.showPage() 273 frame_body = Frame(1*cm,1*cm,width-(2*cm),height-(1.5*cm)) 274 # Insert content table 297 275 298 if tabledata and tableheader: 299 insert_footer(pdf,width,style,footer_text,number_of_pages=2) 300 else: 301 insert_footer(pdf,width,style,footer_text) 302 303 # Insert content table on second page 304 if tabledata and tableheader: 305 pdf.showPage() 306 frame_body = Frame(1*cm,1*cm,width-(2*cm),height-(2*cm)) 276 307 story = [] 308 story.append(Paragraph(view.content_title, style["Heading3"])) 277 309 #story.append(Spacer(1, 12)) 278 310 contenttable = render_table_data(tableheader,tabledata) 279 311 story.append(contenttable) 280 312 frame_body.addFromList(story,pdf) 281 insert_footer(pdf,width,style,footer_text) 313 insert_footer(pdf,width,style,footer_text,number_of_pages=2) 314 282 315 view.response.setHeader( 283 316 'Content-Type', 'application/pdf')
Note: See TracChangeset for help on using the changeset viewer.