Ignore:
Timestamp:
28 Oct 2019, 09:18:21 (5 years ago)
Author:
Henrik Bettermann
Message:

Add getAvailableBeds method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r15695 r15705  
    23402340    notice = ''
    23412341    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
    23422358
    23432359    def update(self, SUBMIT=None):
     
    23812397            # else search for other available beds
    23822398            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)
    23872401            if available_beds:
    23882402                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)
    23982404                # Safety belt for paranoids: Does this bed really exist
    23992405                # in portal?
Note: See TracChangeset for help on using the changeset viewer.