Changeset 7015 for main/waeup.sirp/trunk/src
- Timestamp:
- 7 Nov 2011, 07:43:23 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7009 r7015 20 20 from time import time 21 21 from datetime import date, datetime 22 from zope.event import notify 22 23 from zope.catalog.interfaces import ICatalog 23 24 from zope.component import queryUtility … … 1073 1074 return 1074 1075 1075 @grok.action('Book accommodation')1076 def addBedTicket(self, **data):1077 self.redirect(self.url(self.context, '@@add'))1078 1079 1076 def isStudent(self): 1080 1077 prm = get_principal_role_manager() … … 1090 1087 return sa 1091 1088 1089 class AddBedTicketActionButton(ManageActionButton): 1090 grok.order(1) 1091 grok.context(IStudentAccommodation) 1092 grok.view(AccommodationManageFormPage) 1093 grok.require('waeup.handleStudent') 1094 icon = 'actionicon_home.png' 1095 text = 'Book accommodation' 1096 target = 'add' 1097 1092 1098 class BedTicketAddPage(WAeUPPage): 1093 1099 """ Page to add an online payment ticket … … 1109 1115 1110 1116 # To be sepezified in customization packages 1111 def selectBed(self, student):1112 return getAccommodationDetails(student)1117 def selectBed(self, available_beds): 1118 return selectBed(available_beds) 1113 1119 1114 1120 def update(self, SUBMIT=None): … … 1116 1122 acc_details = self.getAccommodationDetails(student) 1117 1123 if not student.state in acc_details['allowed_states']: 1118 self.flash(" Wrongstate.")1124 self.flash("You are in the wrong registration state.") 1119 1125 self.redirect(self.url(self.context)) 1120 1126 return 1121 1127 if str(student['studycourse'].entry_session) in self.context.keys(): 1122 self.flash('Ticket for %d already created.' 1123 % student['studycourse'].entry_session) 1128 self.flash('You already booked a bed space for the current accommodation session.') 1124 1129 self.redirect(self.url(self.context)) 1125 1130 return … … 1169 1174 bedticket.booking_session = acc_details['booking_session'] 1170 1175 bedticket.bed_type = acc_details['bt'] 1171 bed = sel ectBed(available_beds)1176 bed = self.selectBed(available_beds) 1172 1177 bed.bookBed(student.student_id) 1173 1178 bedticket.bed = bed … … 1202 1207 def title(self): 1203 1208 return 'Bed Ticket %s' % self.context.getSessionString() 1209 1210 class RelocateStudentActionButton(ManageActionButton): 1211 grok.order(1) 1212 grok.context(IBedTicket) 1213 grok.view(BedTicketDisplayFormPage) 1214 grok.require('waeup.manageHostels') 1215 icon = 'actionicon_reload.png' 1216 text = 'Relocate student' 1217 target = 'relocate' 1218 1219 class BedTicketRelocationPage(grok.View): 1220 """ Callback view 1221 """ 1222 grok.context(IBedTicket) 1223 grok.name('relocate') 1224 grok.require('waeup.manageHostels') 1225 1226 # To be sepezified in customization packages 1227 def getAccommodationDetails(self, student): 1228 return getAccommodationDetails(student) 1229 1230 # To be sepezified in customization packages 1231 def selectBed(self, available_beds): 1232 return selectBed(available_beds) 1233 1234 # This update method simulates a valid callback und must be 1235 # specified in the customization package. The parameters must be taken 1236 # from the incoming request. 1237 def update(self): 1238 student = self.context.getStudent() 1239 acc_details = self.getAccommodationDetails(student) 1240 if acc_details['bt'] == self.context.bed_type: 1241 self.flash("Bed category hasn't changed. Student can't be relocated.") 1242 return 1243 # Search a bed and exit if no bed is found or if the student 1244 # has already booked a bed 1245 cat = queryUtility(ICatalog, name='beds_catalog', default=None) 1246 entries = cat.searchResults( 1247 bed_type=(acc_details['bt'],acc_details['bt'])) 1248 available_beds = [ 1249 entry for entry in entries if entry.owner == NOT_OCCUPIED] 1250 if not available_beds: 1251 self.flash('There is no free bed in your category %s.' 1252 % acc_details['bt']) 1253 return 1254 entries = cat.searchResults( 1255 owner=(student.student_id,student.student_id)) 1256 # Rlease old bed 1257 allocated_bed = self.context.bed 1258 allocated_bed.owner = NOT_OCCUPIED 1259 notify(grok.ObjectModifiedEvent(allocated_bed)) 1260 # Alocate new bed 1261 self.context.bed_type = acc_details['bt'] 1262 bed = self.selectBed(available_beds) 1263 bed.bookBed(student.student_id) 1264 self.context.bed = bed 1265 hall_title = bed.__parent__.hostel_name 1266 coordinates = bed.getBedCoordinates()[1:] 1267 block, room_nr, bed_nr = coordinates 1268 self.context.bed_coordinates = '%s, Block %s, Room %s, Bed %s' % ( 1269 hall_title, block, room_nr, bed_nr) 1270 self.flash('Student relocated and new bed booked: %s' 1271 % self.context.bed_coordinates) 1272 self.redirect(self.url(self.context)) 1273 return 1274 1275 def render(self): 1276 self.redirect(self.url(self.context, '@@index')) 1277 return 1204 1278 1205 1279 class StudentHistoryPage(WAeUPPage): -
main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py
r7009 r7015 161 161 self.app['configuration'].addSessionConfiguration(configuration) 162 162 163 # Create a hostel with bed163 # Create a hostel with two beds 164 164 hostel = Hostel() 165 165 hostel.hostel_id = u'hall-1' … … 171 171 bed.owner = NOT_OCCUPIED 172 172 bed.bed_type = u'regular_male_fr' 173 self.app['hostels'][hostel.hostel_id].addBed(bed) 174 bed = Bed() 175 bed.bed_id = u'hall-1_A_101_B' 176 bed.bed_number = 2 177 bed.owner = NOT_OCCUPIED 178 bed.bed_type = u'regular_female_fr' 173 179 self.app['hostels'][hostel.hostel_id].addBed(bed) 174 180 … … 834 840 self.assertMatches('...Course registration has been started...', 835 841 self.browser.contents) 836 self.assertTrue(self.student.state ,'school fee paid')842 self.assertTrue(self.student.state == 'school fee paid') 837 843 return 838 844 … … 858 864 # Managers can use HOS code and book a bed space with it 859 865 self.browser.open(self.acco_student_path) 860 self.browser.get Control("Book accommodation").click()861 self.assertMatches('... Wrong state...',866 self.browser.getLink("Book accommodation").click() 867 self.assertMatches('...You are in the wrong...', 862 868 self.browser.contents) 863 869 IWorkflowInfo(self.student).fireTransition('admit') 864 self.browser.get Control("Book accommodation").click()870 self.browser.getLink("Book accommodation").click() 865 871 self.assertMatches('...Activation Code:...', 866 872 self.browser.contents) … … 872 878 # Bed has been allocated 873 879 bed = self.app['hostels']['hall-1']['hall-1_A_101_A'] 874 self.assertTrue(bed.owner ,self.student_id)880 self.assertTrue(bed.owner == self.student_id) 875 881 # BedTicketAddPage is now blocked 876 self.browser.get Control("Book accommodation").click()877 self.assertMatches('... Ticket for 2004 already created...',882 self.browser.getLink("Book accommodation").click() 883 self.assertMatches('...You already booked a bed space...', 878 884 self.browser.contents) 879 885 # The bed ticket displays the data correctly … … 884 890 self.assertMatches('...regular_male_fr...', self.browser.contents) 885 891 self.assertMatches('...%s...' % pin, self.browser.contents) 886 # Managers cab delete bed tickets 892 # Managers can relocate students 893 self.browser.getLink("Relocate student").click() 894 self.assertMatches( 895 "...Bed category hasn't changed...", self.browser.contents) 896 self.student.sex = u'f' 897 self.browser.getLink("Relocate student").click() 898 self.assertMatches( 899 "...Hall 1, Block A, Room 101, Bed B...", self.browser.contents) 900 bed1 = self.app['hostels']['hall-1']['hall-1_A_101_A'] 901 self.assertTrue(bed1.owner == NOT_OCCUPIED) 902 bed2 = self.app['hostels']['hall-1']['hall-1_A_101_B'] 903 self.assertTrue(bed2.owner == self.student_id) 904 # Managers can delete bed tickets 887 905 self.browser.open(self.acco_student_path) 888 906 ctrl = self.browser.getControl(name='val_id')
Note: See TracChangeset for help on using the changeset viewer.