Changeset 7150
- Timestamp:
- 20 Nov 2011, 07:35:35 (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
r7147 r7150 45 45 IStudentAccommodation, IStudentClearanceEdit, IStudentStudyLevel, 46 46 ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer, 47 IStudentOnlinePayment, IBedTicket 47 IStudentOnlinePayment, IBedTicket, IStudentsUtils 48 48 ) 49 49 from waeup.sirp.students.catalog import search … … 52 52 from waeup.sirp.students.studylevel import StudentStudyLevel, CourseTicket 53 53 from waeup.sirp.students.vocabularies import StudyLevelSource 54 from waeup.sirp.students.utils import (55 get_payment_details, get_accommodation_details, select_bed,56 render_pdf)57 54 from waeup.sirp.browser.resources import toggleall 58 55 from waeup.sirp.authentication import get_principal_role_manager … … 667 664 studentview = StudentBaseDisplayFormPage(self.context.getStudent(), 668 665 self.request) 669 return render_pdf(self,'Course Registration', 'course_registration.pdf', 666 students_utils = getUtility(IStudentsUtils) 667 return students_utils.render_pdf( 668 self,'Course Registration', 'course_registration.pdf', 670 669 self.context.getStudent, studentview) 671 670 … … 939 938 pnav = 4 940 939 941 # To be sepezified in customization packages942 def get_payment_details(self, category, student):943 return get_payment_details(category, student)944 945 940 @grok.action('Create ticket') 946 941 def createTicket(self, **data): … … 954 949 self.redirect(self.url(self.context)) 955 950 return 956 pay_details = self.get_payment_details( 951 students_utils = getUtility(IStudentsUtils) 952 pay_details = students_utils.get_payment_details( 957 953 p_category,student) 958 954 if pay_details['error']: … … 1108 1104 studentview = StudentBaseDisplayFormPage(self.context.getStudent(), 1109 1105 self.request) 1110 return render_pdf(self,'Payment', 'payment_receipt.pdf', 1106 students_utils = getUtility(IStudentsUtils) 1107 return students_utils.render_pdf(self,'Payment', 'payment_receipt.pdf', 1111 1108 self.context.getStudent, studentview) 1112 1109 … … 1217 1214 notice = '' 1218 1215 1219 # To be sepezified in customization packages1220 def get_accommodation_details(self, student):1221 return get_accommodation_details(student)1222 1223 # To be sepezified in customization packages1224 def select_bed(self, available_beds):1225 return select_bed(available_beds)1226 1227 1216 def update(self, SUBMIT=None): 1228 1217 student = self.context.getStudent() 1229 acc_details = self.get_accommodation_details(student) 1218 students_utils = getUtility(IStudentsUtils) 1219 acc_details = students_utils.get_accommodation_details(student) 1230 1220 if not student.state in acc_details['allowed_states']: 1231 1221 self.flash("You are in the wrong registration state.") … … 1264 1254 entry for entry in entries if entry.owner == NOT_OCCUPIED] 1265 1255 if available_beds: 1266 bed = self.select_bed(available_beds) 1256 students_utils = getUtility(IStudentsUtils) 1257 bed = students_utils.select_bed(available_beds) 1267 1258 bed.bookBed(student.student_id) 1268 1259 else: … … 1345 1336 studentview = StudentBaseDisplayFormPage(self.context.getStudent(), 1346 1337 self.request) 1347 return render_pdf(self,'Bed Allocation', 'bed_allocation.pdf', 1338 students_utils = getUtility(IStudentsUtils) 1339 return students_utils.render_pdf( 1340 self,'Bed Allocation', 'bed_allocation.pdf', 1348 1341 self.context.getStudent, studentview) 1349 1342 … … 1364 1357 grok.require('waeup.manageHostels') 1365 1358 1366 # To be sepezified in customization packages1367 def get_accommodation_details(self, student):1368 return get_accommodation_details(student)1369 1370 # To be sepezified in customization packages1371 def select_bed(self, available_beds):1372 return select_bed(available_beds)1373 1374 1359 # Relocate student if student parameters have changed or the bed_type 1375 1360 # of the bed has changed 1376 1361 def update(self): 1377 1362 student = self.context.getStudent() 1378 acc_details = self.get_accommodation_details(student) 1363 students_utils = getUtility(IStudentsUtils) 1364 acc_details = students_utils.get_accommodation_details(student) 1379 1365 if self.context.bed != None and \ 1380 1366 'reserved' in self.context.bed.bed_type: … … 1403 1389 entry for entry in entries if entry.owner == NOT_OCCUPIED] 1404 1390 if available_beds: 1405 new_bed = self.select_bed(available_beds) 1391 students_utils = getUtility(IStudentsUtils) 1392 new_bed = students_utils.select_bed(available_beds) 1406 1393 new_bed.bookBed(student.student_id) 1407 1394 else: -
main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py
r7144 r7150 3 3 import re 4 4 from datetime import datetime 5 from zope.interface import Attribute, invariant 5 from zope.interface import Attribute, invariant, Interface 6 6 from zope.interface.exceptions import Invalid 7 7 from zope import schema … … 26 26 return True 27 27 28 class IStudentsUtils(Interface): 29 """A collection of methods which are subject to customization. 30 31 """ 32 def get_payment_details(category, student): 33 """Get the payment dates of a student for the payment category 34 specified. 35 36 """ 37 38 def get_accommodation_details(student): 39 """Determine the accommodation dates of a student. 40 41 """ 42 43 def select_bed(available_beds): 44 """Select a bed from a list of available beds. 45 46 In the standard configuration we select the first bed found, 47 but can also randomize the selection if we like. 48 """ 49 50 def render_pdf(view, subject='', filename='slip.pdf',): 51 """Render pdf slips for various pages. 52 53 """ 54 28 55 class IStudentsContainer(IWAeUPObject): 29 56 """A students container contains university students. 30 57 31 58 """ 32 33 59 def addStudent(student): 34 60 """Add an IStudent object and subcontainers. … … 68 94 class IStudentNavigation(IWAeUPObject): 69 95 """Interface needed for student navigation. 70 """ 71 96 97 """ 72 98 def getStudent(): 73 99 """Return student object. 100 74 101 """ 75 102 76 103 class IStudentBase(IWAeUPObject): 77 104 """Representation of student base data. 105 78 106 """ 79 107 history = Attribute('Object history, a list of messages') … … 84 112 85 113 def loggerInfo(ob_class, comment): 86 """Adds an INFO message to the log file 114 """Adds an INFO message to the log file. 115 87 116 """ 88 117 … … 141 170 class IStudentClearance(IWAeUPObject): 142 171 """Representation of student clearance data. 143 """ 144 172 173 """ 145 174 date_of_birth = schema.Date( 146 175 title = u'Date of Birth', … … 162 191 class IStudentPersonal(IWAeUPObject): 163 192 """Representation of student personal data. 164 """ 165 193 194 """ 166 195 perm_address = schema.Text( 167 196 title = u'Permanent Address', … … 171 200 class IStudent(IStudentBase,IStudentClearance,IStudentPersonal): 172 201 """Representation of a student. 202 173 203 """ 174 204 175 205 class IStudentUpdateByRegNo(IStudent): 176 206 """Representation of a student. Skip regular reg_number validation. 177 """ 178 207 208 """ 179 209 reg_number = schema.TextLine( 180 210 title = u'Registration Number', … … 185 215 class IStudentUpdateByMatricNo(IStudent): 186 216 """Representation of a student. Skip regular matric_number validation. 187 """ 188 217 218 """ 189 219 matric_number = schema.TextLine( 190 220 title = u'Matriculation Number', … … 197 227 198 228 """ 199 200 229 certificate = schema.Choice( 201 230 title = u'Certificate', … … 256 285 257 286 """ 258 259 287 current_level = schema.Int( 260 288 title = u'Current Level', … … 318 346 319 347 class ICourseTicketAdd(ICourseTicket): 320 """An interface for adding course tickets 348 """An interface for adding course tickets. 321 349 322 350 """ … … 336 364 337 365 """ 338 339 366 bed = Attribute('The bed object.') 340 367 … … 375 402 376 403 def getSessionString(): 377 """Returns the the title of academic_sessions_vocab term 404 """Returns the the title of academic_sessions_vocab term. 405 378 406 """ 379 407 … … 387 415 388 416 """ 389 390 417 p_session = schema.Choice( 391 418 title = u'Payment Session', … … 401 428 class IStudentClearanceEdit(IStudentClearance): 402 429 """Interface needed for restricted editing of student clearance data. 430 403 431 """ 404 432 405 433 class IStudentPersonalEdit(IStudentPersonal): 406 434 """Interface needed for restricted editing of student personal data. 407 """ 435 436 """ -
main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py
r7147 r7150 1 1 """General helper functions for the student section. 2 2 """ 3 from grok import getSite 3 import grok 4 4 from random import SystemRandom as r 5 5 from datetime import date, datetime … … 13 13 from zope.formlib.form import setUpEditWidgets 14 14 from waeup.sirp.interfaces import academic_sessions_vocab 15 from waeup.sirp.students.interfaces import IStudentsUtils 15 16 16 17 SLIP_STYLE = TableStyle( … … 33 34 student['studycourse'].previous_verdict = verdict 34 35 return 35 36 # To be specified in customization packages, see also the view which37 # calls the function.38 def get_payment_details(category, student):39 d = {}40 d['p_item'] = u''41 d['amount'] = 042 d['error'] = u''43 d['p_session'] = student['studycourse'].current_session44 session = str(d['p_session'])45 try:46 academic_session = getSite()['configuration'][session]47 except KeyError:48 d['error'] = u'Session configuration object is not available.'49 return d50 d['surcharge_1'] = academic_session.surcharge_151 d['surcharge_2'] = academic_session.surcharge_252 d['surcharge_3'] = academic_session.surcharge_353 if category == 'schoolfee':54 d['amount'] = academic_session.school_fee_base55 d['p_item'] = student['studycourse'].certificate.code56 elif category == 'clearance':57 d['p_item'] = student['studycourse'].certificate.code58 d['amount'] = academic_session.clearance_fee59 elif category == 'bed_allocation':60 d['p_item'] = get_accommodation_details(student)['bt']61 d['amount'] = academic_session.booking_fee62 return d63 64 # To be specified in customization packages, see also the view which65 # calls the function.66 def get_accommodation_details(student):67 d = {}68 d['error'] = u''69 site_confoguration = getSite()['configuration']70 d['booking_session'] = site_confoguration.accommodation_session71 d['allowed_states'] = site_confoguration.accommodation_states72 session = str(d['booking_session'])73 # Determine bed type74 studycourse = student['studycourse']75 entry_session = studycourse.entry_session76 current_level = studycourse.current_level77 end_level = studycourse.certificate.end_level78 if entry_session == getSite()['configuration'].accommodation_session:79 bt = 'fr'80 elif current_level >= end_level:81 bt = 'fi'82 else:83 bt = 're'84 if student.sex == 'f':85 sex = 'female'86 else:87 sex = 'male'88 special_handling = 'regular'89 d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)90 return d91 92 # To be specified in customization packages, see also view which93 # calls the function.94 # I the standard configuration we select the first bed found,95 # but can also randomize the selection if we like.96 def select_bed(available_beds):97 return available_beds[0]98 36 99 37 def setUpWidgets(view, ignore_request=False): … … 120 58 return table 121 59 122 # To be specified in customization packages, see also view which 123 # calls the function. 124 def render_pdf(view, subject='', filename='slip.pdf', student=None, studentview=None): 125 # (0,0),(-1,-1) = whole table 126 # (0,0),(0,-1) = first column 127 # (-1,0),(-1,-1) = last column 128 # (0,0),(-1,0) = first row 129 # (0,-1),(-1,-1) = last row 60 class StudentsUtils(grok.GlobalUtility): 61 """A collection of methods subject to customization. 62 """ 63 grok.implements(IStudentsUtils) 130 64 131 pdf = canvas.Canvas(filename,pagesize=A4) 132 pdf.setTitle(view.label) 133 pdf.setSubject(subject) 134 pdf.setAuthor('%s (%s)' % (view.request.principal.title, 135 view.request.principal.id)) 136 pdf.setCreator('WAeUP SIRP') 137 width, height = A4 138 style = getSampleStyleSheet() 139 pdf.line(1*cm,height-(1.8*cm),width-(1*cm),height-(1.8*cm)) 65 def get_payment_details(self,category, student): 66 d = {} 67 d['p_item'] = u'' 68 d['amount'] = 0 69 d['error'] = u'' 70 d['p_session'] = student['studycourse'].current_session 71 session = str(d['p_session']) 72 try: 73 academic_session = grok.getSite()['configuration'][session] 74 except KeyError: 75 d['error'] = u'Session configuration object is not available.' 76 return d 77 d['surcharge_1'] = academic_session.surcharge_1 78 d['surcharge_2'] = academic_session.surcharge_2 79 d['surcharge_3'] = academic_session.surcharge_3 80 if category == 'schoolfee': 81 d['amount'] = academic_session.school_fee_base 82 d['p_item'] = student['studycourse'].certificate.code 83 elif category == 'clearance': 84 d['p_item'] = student['studycourse'].certificate.code 85 d['amount'] = academic_session.clearance_fee 86 elif category == 'bed_allocation': 87 d['p_item'] = self.get_accommodation_details(student)['bt'] 88 d['amount'] = academic_session.booking_fee 89 return d 140 90 141 story = [] 142 frame_header = Frame(1*cm,1*cm,width-(1.7*cm),height-(1.7*cm)) 143 header_title = getattr(getSite(), 'name', u'Sample University') 144 story.append(Paragraph(header_title, style["Heading1"])) 145 frame_header.addFromList(story,pdf) 91 def get_accommodation_details(self, student): 92 d = {} 93 d['error'] = u'' 94 site_confoguration = grok.getSite()['configuration'] 95 d['booking_session'] = site_confoguration.accommodation_session 96 d['allowed_states'] = site_confoguration.accommodation_states 97 session = str(d['booking_session']) 98 # Determine bed type 99 studycourse = student['studycourse'] 100 entry_session = studycourse.entry_session 101 current_level = studycourse.current_level 102 end_level = studycourse.certificate.end_level 103 if entry_session == grok.getSite()['configuration'].accommodation_session: 104 bt = 'fr' 105 elif current_level >= end_level: 106 bt = 'fi' 107 else: 108 bt = 're' 109 if student.sex == 'f': 110 sex = 'female' 111 else: 112 sex = 'male' 113 special_handling = 'regular' 114 d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) 115 return d 146 116 147 story = [] 148 frame_body = Frame(1*cm,1*cm,width-(2*cm),height-(3.5*cm)) 149 story.append(Paragraph(view.label, style["Heading2"])) 150 #story.append(HRFlowable()) 151 if student: 117 # In the standard configuration we select the first bed found, 118 # but can also randomize the selection if we like. 119 def select_bed(self, available_beds): 120 return available_beds[0] 121 122 def render_pdf(self, view, subject='', filename='slip.pdf', 123 student=None, studentview=None): 124 # (0,0),(-1,-1) = whole table 125 # (0,0),(0,-1) = first column 126 # (-1,0),(-1,-1) = last column 127 # (0,0),(-1,0) = first row 128 # (0,-1),(-1,-1) = last row 129 130 pdf = canvas.Canvas(filename,pagesize=A4) 131 pdf.setTitle(view.label) 132 pdf.setSubject(subject) 133 pdf.setAuthor('%s (%s)' % (view.request.principal.title, 134 view.request.principal.id)) 135 pdf.setCreator('WAeUP SIRP') 136 width, height = A4 137 style = getSampleStyleSheet() 138 pdf.line(1*cm,height-(1.8*cm),width-(1*cm),height-(1.8*cm)) 139 140 story = [] 141 frame_header = Frame(1*cm,1*cm,width-(1.7*cm),height-(1.7*cm)) 142 header_title = getattr(grok.getSite(), 'name', u'Sample University') 143 story.append(Paragraph(header_title, style["Heading1"])) 144 frame_header.addFromList(story,pdf) 145 146 story = [] 147 frame_body = Frame(1*cm,1*cm,width-(2*cm),height-(3.5*cm)) 148 story.append(Paragraph(view.label, style["Heading2"])) 149 #story.append(HRFlowable()) 150 if student: 151 story.append(Spacer(1, 18)) 152 studenttable = render_student_data(student, studentview) 153 story.append(studenttable) 152 154 story.append(Spacer(1, 18)) 153 studenttable = render_student_data(student, studentview) 154 story.append(studenttable) 155 story.append(Spacer(1, 18)) 156 setUpWidgets(view) 157 data = [] 158 for widget in view.widgets: 159 f_label = '<font size=12>%s</font>:' % widget.label.strip() 160 f_label = Paragraph(f_label, style["Normal"]) 161 f_text = '<font size=12>%s</font>' % widget() 162 f_text = Paragraph(f_text, style["Normal"]) 163 data.append([f_label,f_text]) 164 table = Table(data,style=SLIP_STYLE) 165 story.append(table) 166 frame_body.addFromList(story,pdf) 155 setUpWidgets(view) 156 data = [] 157 for widget in view.widgets: 158 f_label = '<font size=12>%s</font>:' % widget.label.strip() 159 f_label = Paragraph(f_label, style["Normal"]) 160 f_text = '<font size=12>%s</font>' % widget() 161 f_text = Paragraph(f_text, style["Normal"]) 162 data.append([f_label,f_text]) 163 table = Table(data,style=SLIP_STYLE) 164 story.append(table) 165 frame_body.addFromList(story,pdf) 167 166 168 story = []169 frame_footer = Frame(1*cm,0,width-(2*cm),1*cm)170 timestamp = datetime.now().strftime("%d/%m/%Y %H:%M:%S")171 f_text = '<font size=10>%s</font>' % timestamp172 story.append(Paragraph(f_text, style["Normal"]))173 frame_footer.addFromList(story,pdf)167 story = [] 168 frame_footer = Frame(1*cm,0,width-(2*cm),1*cm) 169 timestamp = datetime.now().strftime("%d/%m/%Y %H:%M:%S") 170 f_text = '<font size=10>%s</font>' % timestamp 171 story.append(Paragraph(f_text, style["Normal"])) 172 frame_footer.addFromList(story,pdf) 174 173 175 view.response.setHeader(176 'Content-Type', 'application/pdf')177 return pdf.getpdfdata()174 view.response.setHeader( 175 'Content-Type', 'application/pdf') 176 return pdf.getpdfdata()
Note: See TracChangeset for help on using the changeset viewer.