Changeset 15705 for main


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

Add getAvailableBeds method.

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  
    138138            available_beds = [
    139139                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
    140146            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)
    146148                new_bed.bookBed(student.student_id)
    147149            else:
  • 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?
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r15664 r15705  
    301301        constraint=validate_email,
    302302        )
     303
    303304    phone = PhoneNumber(
    304305        title = _(u'Phone'),
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r15694 r15705  
    33603360        self.browser.getControl("Create bed ticket").click()
    33613361        # 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.'
    33633363            in self.browser.contents)
    33643364        self.browser.getControl(name="hostel").value = ['hall-1']
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r15685 r15705  
    665665        return
    666666
    667     def selectBed(self, available_beds, desired_hostel=None):
     667    def selectBed(self, available_beds):
    668668        """Select a bed from a filtered list of available beds.
    669669        In the base configuration beds are sorted by the sort id
     
    673673        sorted_beds = sorted(available_beds,
    674674                key=lambda bed: 1000 * bed.__parent__.sort_id + bed.bed_number)
    675         if desired_hostel and desired_hostel != 'no':
    676             # Filter desired hostel beds
    677             filtered_beds = [bed for bed in sorted_beds
    678                              if bed.bed_id.startswith(desired_hostel)]
    679             if not filtered_beds:
    680                 return
    681             return filtered_beds[0]
    682675        return sorted_beds[0]
    683676
Note: See TracChangeset for help on using the changeset viewer.