Changeset 15709
- Timestamp:
- 29 Oct 2019, 06:02:24 (5 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r15705 r15709 2333 2333 grok.name('add') 2334 2334 grok.require('waeup.handleAccommodation') 2335 grok.template('enterpin')2335 #grok.template('enterpin') 2336 2336 ac_prefix = 'HOS' 2337 2337 label = _('Add bed ticket') … … 2342 2342 with_bedselection = True 2343 2343 2344 def getAvailableBeds(self, acc_details, desired_hostel): 2344 @property 2345 def getAvailableBeds(self): 2345 2346 """Get a list of all available beds. 2346 2347 """ 2347 2348 cat = queryUtility(ICatalog, name='beds_catalog', default=None) 2348 2349 entries = cat.searchResults( 2349 bed_type=( acc_details['bt'],acc_details['bt']))2350 bed_type=(self.acc_details['bt'],self.acc_details['bt'])) 2350 2351 available_beds = [ 2351 2352 entry for entry in entries if entry.owner == NOT_OCCUPIED] 2353 desired_hostel = self.context.desired_hostel 2354 # Filter desired hostel beds 2352 2355 if desired_hostel and desired_hostel != 'no': 2353 # Filter desired hostel beds2354 2356 filtered_beds = [bed for bed in available_beds 2355 2357 if bed.bed_id.startswith(desired_hostel)] 2356 return filtered_beds 2358 available_beds = filtered_beds 2359 # Add legible bed coordinates 2360 for bed in available_beds: 2361 hall_title = bed.__parent__.hostel_name 2362 coordinates = bed.coordinates[1:] 2363 block, room_nr, bed_nr = coordinates 2364 bed.temp_bed_coordinates = _( 2365 '${a}, Block ${b}, Room ${c}, Bed ${d}', mapping = { 2366 'a':hall_title, 'b':block, 2367 'c':room_nr, 'd':bed_nr}) 2357 2368 return available_beds 2358 2369 … … 2360 2371 student = self.context.student 2361 2372 students_utils = getUtility(IStudentsUtils) 2362 acc_details = students_utils.getAccommodationDetails(student)2373 self.acc_details = students_utils.getAccommodationDetails(student) 2363 2374 error_message = students_utils.checkAccommodationRequirements( 2364 student, acc_details) 2375 student, self.acc_details) 2376 cat = queryUtility(ICatalog, name='beds_catalog', default=None) 2377 entries = cat.searchResults( 2378 owner=(student.student_id,student.student_id)) 2379 self.show_available_beds = False 2365 2380 if error_message: 2366 2381 self.flash(error_message, type="warning") … … 2370 2385 self.ac_series = self.request.form.get('ac_series', None) 2371 2386 self.ac_number = self.request.form.get('ac_number', None) 2387 available_beds = self.getAvailableBeds 2372 2388 if SUBMIT is None: 2389 if self.with_bedselection and available_beds and not len(entries): 2390 self.show_available_beds = True 2373 2391 return 2374 2392 if self.with_ac: … … 2379 2397 return 2380 2398 # Search and book bed 2381 cat = queryUtility(ICatalog, name='beds_catalog', default=None)2382 entries = cat.searchResults(2383 owner=(student.student_id,student.student_id))2384 2399 if len(entries): 2385 # If bed space has been manually allocated use this bed 2400 # If bed space has been manually allocated use this bed ... 2386 2401 manual = True 2387 bed = [entry for entry in entries][0] 2388 # Safety belt for paranoids: Does this bed really exist on portal? 2389 # XXX: Can be remove if nobody complains. 2390 if bed.__parent__.__parent__ is None: 2391 self.flash(_('System error: Please contact the adminsitrator.'), 2392 type="danger") 2393 self.context.writeLogMessage( 2394 self, 'fatal error: %s' % bed.bed_id) 2395 return 2396 else: 2397 # else search for other available beds 2402 bed = liest(entries)[0] 2403 else: 2404 # ... else search for available beds 2398 2405 manual = False 2399 available_beds = self.getAvailableBeds( 2400 acc_details, self.context.desired_hostel) 2401 if available_beds: 2406 selected_bed = self.request.form.get('bed', None) 2407 if selected_bed: 2408 # Use selected bed 2409 beds = cat.searchResults( 2410 bed_id=(selected_bed,selected_bed)) 2411 bed = list(beds)[0] 2412 bed.bookBed(student.student_id) 2413 elif available_beds: 2414 # Select bed according to selectBed method 2402 2415 students_utils = getUtility(IStudentsUtils) 2403 2416 bed = students_utils.selectBed(available_beds) 2404 # Safety belt for paranoids: Does this bed really exist2405 # in portal?2406 # XXX: Can be remove if nobody complains.2407 if bed.__parent__.__parent__ is None:2408 self.flash(_(2409 'System error: Please contact the administrator.'),2410 type="warning")2411 self.context.writeLogMessage(2412 self, 'fatal error: %s' % bed.bed_id)2413 return2414 2417 bed.bookBed(student.student_id) 2415 2418 else: 2416 2419 self.flash(_('There is no free bed in your category ${a}.', 2417 mapping = {'a': acc_details['bt']}), type="warning")2420 mapping = {'a':self.acc_details['bt']}), type="warning") 2418 2421 self.redirect(self.url(self.context)) 2419 2422 return … … 2448 2451 if self.with_ac: 2449 2452 bedticket.booking_code = pin 2450 bedticket.booking_session = acc_details['booking_session']2451 bedticket.bed_type = acc_details['bt']2453 bedticket.booking_session = self.acc_details['booking_session'] 2454 bedticket.bed_type = self.acc_details['bt'] 2452 2455 bedticket.bed = bed 2453 2456 hall_title = bed.__parent__.hostel_name -
main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/accommodationmanagepage.pt
r13480 r15709 5 5 <br /> 6 6 <p i18n:translate=""> 7 Select and <strong>save the desired hostel</strong> before booking acommodation.8 Your choice cannot be changed afterwards.7 Select and <strong>save the desired hostel</strong> before creating 8 a bed ticket. Your choice cannot be changed afterwards. 9 9 </p> 10 10 <div class="form-inline"> -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r15705 r15709 3358 3358 self.browser.getControl(name="ac_series").value = sfeseries 3359 3359 self.browser.getControl(name="ac_number").value = sfenumber 3360 # There is no free bed space and the bed selector does not appear 3361 self.assertFalse('<option value="hall-1_A_101_A">' 3362 in self.browser.contents) 3360 3363 self.browser.getControl("Create bed ticket").click() 3361 3364 # Hostel 2 has only a bed for women. … … 3375 3378 self.assertTrue(bed.owner == NOT_OCCUPIED) 3376 3379 ac.owner = self.student_id 3380 self.browser.open(self.acco_path + '/add') 3377 3381 self.browser.getControl(name="ac_series").value = sfeseries 3378 3382 self.browser.getControl(name="ac_number").value = sfenumber 3383 # Bed can be selected 3384 self.browser.getControl(name="bed").value = ['hall-1_A_101_A'] 3379 3385 self.browser.getControl("Create bed ticket").click() 3380 self.assert Matches('...Hall 1, Block A, Room 101, Bed A...',3381 3386 self.assertTrue('Bed ticket created and bed booked' 3387 in self.browser.contents) 3382 3388 # Bed has been allocated. 3383 3389 self.assertTrue(bed.owner == self.student_id)
Note: See TracChangeset for help on using the changeset viewer.