Changeset 6992 for main/waeup.sirp/trunk/src
- Timestamp:
- 3 Nov 2011, 15:40:11 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/students
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/accommodation.py
r6989 r6992 17 17 Container which contains the (student) accommodation objects. 18 18 """ 19 from datetime import datetime 19 20 import grok 20 21 from grok import index … … 57 58 def __init__(self): 58 59 super(BedTicket, self).__init__() 60 self.booking_date = datetime.now() 59 61 return 60 62 … … 63 65 64 66 BedTicket = attrs_to_fields(BedTicket) 67 68 # Bed tickets must be importable. So we might need a factory. 69 class BedTicketFactory(grok.GlobalUtility): 70 """A factory for bed tickets. 71 """ 72 grok.implements(IFactory) 73 grok.name(u'waeup.BedTicket') 74 title = u"Create a new bed ticket.", 75 description = u"This factory instantiates new bed ticket instances." 76 77 def __call__(self, *args, **kw): 78 return BedTicket() 79 80 def getInterfaces(self): 81 return implementedBy(BedTicket) -
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r6953 r6992 40 40 IStudentAccommodation, IStudentClearanceEdit, IStudentStudyLevel, 41 41 ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer, 42 IStudentOnlinePayment 42 IStudentOnlinePayment, IBedTicket 43 43 ) 44 44 from waeup.sirp.students.catalog import search 45 from waeup.sirp.students.workflow import CLEARANCE, RETURNING, CLEARED 45 from waeup.sirp.students.workflow import ( 46 CLEARANCE, RETURNING, CLEARED, REGISTERED, VALIDATED) 46 47 from waeup.sirp.students.studylevel import StudentStudyLevel, CourseTicket 47 48 from waeup.sirp.students.vocabularies import StudyLevelSource 48 49 from waeup.sirp.students.utils import getPaymentDetails 50 from waeup.sirp.students.utils import getAccommodationDetails 49 51 from waeup.sirp.browser.resources import toggleall 50 52 from waeup.sirp.authentication import get_principal_role_manager … … 846 848 deleted = [] 847 849 for id in child_id: 848 # Students are not allowed to remove payment usedtickets850 # Students are not allowed to remove used payment tickets 849 851 if not self.unremovable(self.context[id]): 850 852 try: … … 971 973 return 972 974 973 class AccommodationDisplayFormPage(WAeUPDisplayFormPage): 974 """ Page to display the student accommodation data 975 # We don't need the display form page yet 976 #class AccommodationDisplayFormPage(WAeUPDisplayFormPage): 977 # """ Page to display the student accommodation data 978 # """ 979 # grok.context(IStudentAccommodation) 980 # grok.name('xxx') 981 # grok.require('waeup.viewStudent') 982 # form_fields = grok.AutoFields(IStudentAccommodation) 983 # #grok.template('accommodationpage') 984 # title = 'Accommodation' 985 # pnav = 4 986 987 # @property 988 # def label(self): 989 # return '%s: Accommodation Data' % self.context.__parent__.fullname 990 991 # This manage form page is for both students and students officers. 992 class AccommodationManageFormPage(WAeUPEditFormPage): 993 """ Page to manage the bed tickets 975 994 """ 976 995 grok.context(IStudentAccommodation) 977 996 grok.name('index') 978 grok.require('waeup. viewStudent')997 grok.require('waeup.handleStudent') 979 998 form_fields = grok.AutoFields(IStudentAccommodation) 980 #grok.template('accommodationpage')999 grok.template('accommodationmanagepage') 981 1000 title = 'Accommodation' 982 1001 pnav = 4 983 1002 1003 def unremovable(self): 1004 prm = get_principal_role_manager() 1005 roles = [x[0] for x in prm.getRolesForPrincipal(self.request.principal.id)] 1006 return ('waeup.Student' in roles) 1007 1008 def formatDatetime(self,datetimeobj): 1009 if isinstance(datetimeobj, datetime): 1010 return datetimeobj.strftime("%Y-%m-%d %H:%M:%S") 1011 else: 1012 return None 1013 984 1014 @property 985 1015 def label(self): 986 return '%s: Accommodation Data' % self.context.__parent__.fullname 1016 return '%s: Accommodation' % self.context.__parent__.fullname 1017 1018 def update(self): 1019 super(AccommodationManageFormPage, self).update() 1020 datatable.need() 1021 return 1022 1023 # We need an event handler which releases the bed space too. 1024 @grok.action('Remove selected tickets') 1025 def delBedTicket(self, **data): 1026 form = self.request.form 1027 if form.has_key('val_id'): 1028 child_id = form['val_id'] 1029 else: 1030 self.flash('No bed ticket selected.') 1031 self.redirect(self.url(self.context)) 1032 return 1033 if not isinstance(child_id, list): 1034 child_id = [child_id] 1035 deleted = [] 1036 for id in child_id: 1037 # Students are not allowed to remove bed tickets 1038 if not self.unremovable(): 1039 try: 1040 del self.context[id] 1041 deleted.append(id) 1042 except: 1043 self.flash('Could not delete %s: %s: %s' % ( 1044 id, sys.exc_info()[0], sys.exc_info()[1])) 1045 if len(deleted): 1046 self.flash('Successfully removed: %s' % ', '.join(deleted)) 1047 write_log_message(self,'removed: % s' % ', '.join(deleted)) 1048 self.redirect(self.url(self.context)) 1049 return 1050 1051 @grok.action('Add bed ticket') 1052 def addBedTicket(self, **data): 1053 self.redirect(self.url(self.context, '@@add')) 1054 1055 class BedTicketAddPage(WAeUPPage): 1056 """ Page to add an online payment ticket 1057 """ 1058 grok.context(IStudentAccommodation) 1059 grok.name('add') 1060 grok.require('waeup.handleStudent') 1061 grok.template('enterpin') 1062 ac_prefix = 'CLR' 1063 label = 'Add bed ticket' 1064 title = 'Add bed ticket' 1065 pnav = 4 1066 buttonname = 'Create bed ticket' 1067 1068 # To be sepezified in customization packages 1069 def getAccommodationDetails(self, student): 1070 return getAccommodationDetails(student) 1071 1072 def update(self, SUBMIT=None): 1073 (booking_session, booking_fee, maint_fee, allowed_states, 1074 error) = self.getAccommodationDetails(self.context.__parent__) 1075 if not self.context.getStudent().state in allowed_states: 1076 self.flash("Wrong state.") 1077 self.redirect(self.url(self.context)) 1078 return 1079 self.ac_series = self.request.form.get('ac_series', None) 1080 self.ac_number = self.request.form.get('ac_number', None) 1081 1082 if SUBMIT is None: 1083 return 1084 pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number) 1085 code = get_access_code(pin) 1086 if not code: 1087 self.flash('Activation code is invalid.') 1088 return 1089 # Mark pin as used (this also fires a pin related transition) 1090 if code.state == USED: 1091 self.flash('Activation code has already been used.') 1092 return 1093 else: 1094 comment = u"AC invalidated for %s" % self.context.getStudent().student_id 1095 # Here we know that the ac is in state initialized so we do not 1096 # expect an exception, but the owner might be different 1097 if not invalidate_accesscode( 1098 pin,comment,self.context.getStudent().student_id): 1099 self.flash('You are not the owner of this access code.') 1100 return 1101 bedticket = createObject(u'waeup.BedTicket') 1102 #self.applyData(bedticket, **data) 1103 bedticket.booking_code = pin 1104 bedticket.bed = u'Test Bed' 1105 self.context['test'] = bedticket 1106 self.flash('Bed ticket created.') 1107 self.redirect(self.url(self.context)) 1108 return 987 1109 988 1110 class StudentHistoryPage(WAeUPPage): -
main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py
r6989 r6992 320 320 """ 321 321 322 bed = schema.TextLine( 323 title = u'Bed', 324 default = None, 325 required = False, 326 ) 327 328 booking_session = schema.Choice( 329 title = u'Session', 330 source = academic_sessions_vocab, 331 default = None, 332 required = True, 333 ) 334 335 booking_date = schema.Datetime( 336 title = u'Booking Date', 337 required = False, 338 readonly = False, 339 ) 340 341 booking_code = schema.TextLine( 342 title = u'Booking Activation Code', 343 default = u'', 344 required = False, 345 readonly = False, 346 ) 347 348 booking_fee =schema.Int( 349 title = u'Booking Fee', 350 default = 0, 351 required = False, 352 readonly = False, 353 ) 354 355 maint_date = schema.Datetime( 356 title = u'Maintenance Fee Payment Date', 357 required = False, 358 readonly = False, 359 ) 360 361 maint_code = schema.TextLine( 362 title = u'Maintenance Fee Payment Code', 363 default = u'Certificate XYZ', 364 required = False, 365 readonly = False, 366 ) 367 368 maint_fee = schema.Int( 369 title = u'Maintenance Fee', 370 default = 0, 371 required = False, 372 readonly = False, 373 ) 374 322 375 class IStudentPaymentsContainer(IPaymentsContainer): 323 376 """A container for student payment objects. -
main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py
r6929 r6992 47 47 return (amount, p_item, p_session, 48 48 surcharge_1, surcharge_2, surcharge_3, error) 49 50 # To be specified in customization packages. 51 # This function is for demonstration and testing only. 52 def getAccommodationDetails(student): 53 bookin_fee = maint_fee = 0 54 error = u'' 55 booking_session = getSite()['configuration'].accommodation_session 56 allowed_states = getSite()['configuration'].accommodation_states 57 session = str(booking_session) 58 try: 59 academic_session = getSite()['configuration'][session] 60 except KeyError: 61 error = u'Session configuration object is not available.' 62 return (booking_session, booking_fee, maint_fee, allowed_states, 63 error) 64 booking_fee = academic_session.booking_fee 65 maint_fee = academic_session.maint_fee 66 return booking_session, booking_fee, maint_fee, allowed_states, error
Note: See TracChangeset for help on using the changeset viewer.