Changeset 15705 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 28 Oct 2019, 09:18:21 (5 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/accommodation.py
r15310 r15705 138 138 available_beds = [ 139 139 entry for entry in entries if entry.owner == NOT_OCCUPIED] 140 desired_hostel = self.__parent__.desired_hostel 141 if desired_hostel and desired_hostel != 'no': 142 # Filter desired hostel beds 143 filtered_beds = [bed for bed in available_beds 144 if bed.bed_id.startswith(desired_hostel)] 145 available_beds = filtered_beds 140 146 if available_beds: 141 new_bed = students_utils.selectBed( 142 available_beds, self.__parent__.desired_hostel) 143 if new_bed is None: 144 return False, _( 145 'There is no free bed in your desired hostel.') 147 new_bed = students_utils.selectBed(available_beds) 146 148 new_bed.bookBed(student.student_id) 147 149 else: -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r15695 r15705 2340 2340 notice = '' 2341 2341 with_ac = True 2342 with_bedselection = True 2343 2344 def getAvailableBeds(self, acc_details, desired_hostel): 2345 """Get a list of all available beds. 2346 """ 2347 cat = queryUtility(ICatalog, name='beds_catalog', default=None) 2348 entries = cat.searchResults( 2349 bed_type=(acc_details['bt'],acc_details['bt'])) 2350 available_beds = [ 2351 entry for entry in entries if entry.owner == NOT_OCCUPIED] 2352 if desired_hostel and desired_hostel != 'no': 2353 # Filter desired hostel beds 2354 filtered_beds = [bed for bed in available_beds 2355 if bed.bed_id.startswith(desired_hostel)] 2356 return filtered_beds 2357 return available_beds 2342 2358 2343 2359 def update(self, SUBMIT=None): … … 2381 2397 # else search for other available beds 2382 2398 manual = False 2383 entries = cat.searchResults( 2384 bed_type=(acc_details['bt'],acc_details['bt'])) 2385 available_beds = [ 2386 entry for entry in entries if entry.owner == NOT_OCCUPIED] 2399 available_beds = self.getAvailableBeds( 2400 acc_details, self.context.desired_hostel) 2387 2401 if available_beds: 2388 2402 students_utils = getUtility(IStudentsUtils) 2389 bed = students_utils.selectBed( 2390 available_beds, self.context.desired_hostel) 2391 if bed is None: 2392 self.flash(_( 2393 'There is no free bed in your desired hostel. ' 2394 'Please try another hostel.'), 2395 type="warning") 2396 self.redirect(self.url(self.context)) 2397 return 2403 bed = students_utils.selectBed(available_beds) 2398 2404 # Safety belt for paranoids: Does this bed really exist 2399 2405 # in portal? -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r15664 r15705 301 301 constraint=validate_email, 302 302 ) 303 303 304 phone = PhoneNumber( 304 305 title = _(u'Phone'), -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r15694 r15705 3360 3360 self.browser.getControl("Create bed ticket").click() 3361 3361 # Hostel 2 has only a bed for women. 3362 self.assertTrue('There is no free bed in your desired hostel'3362 self.assertTrue('There is no free bed in your category regular_male_fr.' 3363 3363 in self.browser.contents) 3364 3364 self.browser.getControl(name="hostel").value = ['hall-1'] -
main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
r15685 r15705 665 665 return 666 666 667 def selectBed(self, available_beds , desired_hostel=None):667 def selectBed(self, available_beds): 668 668 """Select a bed from a filtered list of available beds. 669 669 In the base configuration beds are sorted by the sort id … … 673 673 sorted_beds = sorted(available_beds, 674 674 key=lambda bed: 1000 * bed.__parent__.sort_id + bed.bed_number) 675 if desired_hostel and desired_hostel != 'no':676 # Filter desired hostel beds677 filtered_beds = [bed for bed in sorted_beds678 if bed.bed_id.startswith(desired_hostel)]679 if not filtered_beds:680 return681 return filtered_beds[0]682 675 return sorted_beds[0] 683 676
Note: See TracChangeset for help on using the changeset viewer.