Changeset 7068 for main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
- Timestamp:
- 10 Nov 2011, 18:56:18 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7061 r7068 186 186 self.flash('Empty search string.') 187 187 return 188 if self.searchtype == 'current_session': 189 self.searchterm = int(self.searchterm) 188 190 self.hitlist = search(query=self.searchterm, 189 191 searchtype=self.searchtype, view=self) … … 1178 1180 deleted = [] 1179 1181 for id in child_id: 1180 try: 1181 del self.context[id] 1182 deleted.append(id) 1183 except: 1184 self.flash('Could not delete %s: %s: %s' % ( 1185 id, sys.exc_info()[0], sys.exc_info()[1])) 1182 del self.context[id] 1183 deleted.append(id) 1186 1184 if len(deleted): 1187 1185 self.flash('Successfully removed: %s' % ', '.join(deleted)) … … 1295 1293 coordinates = bed.getBedCoordinates()[1:] 1296 1294 block, room_nr, bed_nr = coordinates 1297 bedticket.bed_coordinates = '%s, Block %s, Room %s, Bed %s ' % (1298 hall_title, block, room_nr, bed_nr )1295 bedticket.bed_coordinates = '%s, Block %s, Room %s, Bed %s (%s)' % ( 1296 hall_title, block, room_nr, bed_nr, bed.bed_type) 1299 1297 key = str(acc_details['booking_session']) 1300 1298 self.context[key] = bedticket … … 1381 1379 student = self.context.getStudent() 1382 1380 acc_details = self.getAccommodationDetails(student) 1381 if self.context.bed != None and \ 1382 'reserved' in self.context.bed.bed_type: 1383 self.flash("Students in reserved beds can't be relocated.") 1384 self.redirect(self.url(self.context)) 1385 return 1383 1386 if acc_details['bt'] == self.context.bed_type and \ 1387 self.context.bed != None and \ 1384 1388 self.context.bed.bed_type == self.context.bed_type: 1385 self.flash("Bed category hasn't changed. Student can't be relocated.") 1386 return 1387 # Search a bed and exit if no bed is found 1389 self.flash("Student can't be relocated.") 1390 self.redirect(self.url(self.context)) 1391 return 1392 # Search a bed 1388 1393 cat = queryUtility(ICatalog, name='beds_catalog', default=None) 1389 1394 entries = cat.searchResults( 1390 bed_type=(acc_details['bt'],acc_details['bt'])) 1391 available_beds = [ 1392 entry for entry in entries if entry.owner == NOT_OCCUPIED] 1393 if not available_beds: 1394 self.flash('There is no free bed in your category %s.' 1395 % acc_details['bt']) 1396 return 1397 #entries = cat.searchResults( 1398 # owner=(student.student_id,student.student_id)) 1399 # Rlease old bed 1400 try: 1401 allocated_bed = self.context.bed 1402 allocated_bed.owner = NOT_OCCUPIED 1403 notify(grok.ObjectModifiedEvent(allocated_bed)) 1404 except AttributeError: 1405 # Cannot happen but anyway... 1406 pass 1395 owner=(student.student_id,student.student_id)) 1396 if len(entries) and self.context.bed == None: 1397 # If booking has been cancelled but other bed space has been 1398 # manually allocated after cancellation use this bed 1399 new_bed = [entry for entry in entries][0] 1400 else: 1401 # Search for other available beds 1402 entries = cat.searchResults( 1403 bed_type=(acc_details['bt'],acc_details['bt'])) 1404 available_beds = [ 1405 entry for entry in entries if entry.owner == NOT_OCCUPIED] 1406 if available_beds: 1407 new_bed = self.selectBed(available_beds) 1408 new_bed.bookBed(student.student_id) 1409 else: 1410 self.flash('There is no free bed in your category %s.' 1411 % acc_details['bt']) 1412 self.redirect(self.url(self.context)) 1413 return 1414 # Rlease old bed if exists 1415 if self.context.bed != None: 1416 self.context.bed.owner = NOT_OCCUPIED 1417 notify(grok.ObjectModifiedEvent(self.context.bed)) 1407 1418 # Alocate new bed 1408 1419 self.context.bed_type = acc_details['bt'] 1409 bed = self.selectBed(available_beds) 1410 bed.bookBed(student.student_id) 1411 self.context.bed = bed 1412 hall_title = bed.__parent__.hostel_name 1413 coordinates = bed.getBedCoordinates()[1:] 1420 self.context.bed = new_bed 1421 hall_title = new_bed.__parent__.hostel_name 1422 coordinates = new_bed.getBedCoordinates()[1:] 1414 1423 block, room_nr, bed_nr = coordinates 1415 self.context.bed_coordinates = '%s, Block %s, Room %s, Bed %s' % ( 1416 hall_title, block, room_nr, bed_nr) 1417 self.flash('Student relocated and new bed booked: %s' 1418 % self.context.bed_coordinates) 1424 self.context.bed_coordinates = '%s, Block %s, Room %s, Bed %s (%s)' % ( 1425 hall_title, block, room_nr, bed_nr, new_bed.bed_type) 1426 self.flash('Student relocated: %s' % self.context.bed_coordinates) 1419 1427 self.redirect(self.url(self.context)) 1420 1428 return 1421 1429 1422 1430 def render(self): 1423 self.redirect(self.url(self.context, '@@index'))1431 #self.redirect(self.url(self.context, '@@index')) 1424 1432 return 1425 1433
Note: See TracChangeset for help on using the changeset viewer.