Ignore:
Timestamp:
29 Oct 2019, 06:02:24 (5 years ago)
Author:
Henrik Bettermann
Message:

Implement bed selector.

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  
    23332333    grok.name('add')
    23342334    grok.require('waeup.handleAccommodation')
    2335     grok.template('enterpin')
     2335    #grok.template('enterpin')
    23362336    ac_prefix = 'HOS'
    23372337    label = _('Add bed ticket')
     
    23422342    with_bedselection = True
    23432343
    2344     def getAvailableBeds(self, acc_details, desired_hostel):
     2344    @property
     2345    def getAvailableBeds(self):
    23452346        """Get a list of all available beds.
    23462347        """
    23472348        cat = queryUtility(ICatalog, name='beds_catalog', default=None)
    23482349        entries = cat.searchResults(
    2349             bed_type=(acc_details['bt'],acc_details['bt']))
     2350            bed_type=(self.acc_details['bt'],self.acc_details['bt']))
    23502351        available_beds = [
    23512352            entry for entry in entries if entry.owner == NOT_OCCUPIED]
     2353        desired_hostel = self.context.desired_hostel
     2354        # Filter desired hostel beds
    23522355        if desired_hostel and desired_hostel != 'no':
    2353             # Filter desired hostel beds
    23542356            filtered_beds = [bed for bed in available_beds
    23552357                             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})
    23572368        return available_beds
    23582369
     
    23602371        student = self.context.student
    23612372        students_utils = getUtility(IStudentsUtils)
    2362         acc_details  = students_utils.getAccommodationDetails(student)
     2373        self.acc_details  = students_utils.getAccommodationDetails(student)
    23632374        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
    23652380        if error_message:
    23662381            self.flash(error_message, type="warning")
     
    23702385            self.ac_series = self.request.form.get('ac_series', None)
    23712386            self.ac_number = self.request.form.get('ac_number', None)
     2387        available_beds = self.getAvailableBeds
    23722388        if SUBMIT is None:
     2389            if self.with_bedselection and available_beds and not len(entries):
     2390                self.show_available_beds = True
    23732391            return
    23742392        if self.with_ac:
     
    23792397                return
    23802398        # 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))
    23842399        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 ...
    23862401            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
    23982405            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
    24022415                students_utils = getUtility(IStudentsUtils)
    24032416                bed = students_utils.selectBed(available_beds)
    2404                 # Safety belt for paranoids: Does this bed really exist
    2405                 # 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                     return
    24142417                bed.bookBed(student.student_id)
    24152418            else:
    24162419                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")
    24182421                self.redirect(self.url(self.context))
    24192422                return
     
    24482451        if self.with_ac:
    24492452            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']
    24522455        bedticket.bed = bed
    24532456        hall_title = bed.__parent__.hostel_name
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/accommodationmanagepage.pt

    r13480 r15709  
    55    <br />
    66    <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.
    99    </p>
    1010    <div class="form-inline">
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r15705 r15709  
    33583358        self.browser.getControl(name="ac_series").value = sfeseries
    33593359        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)
    33603363        self.browser.getControl("Create bed ticket").click()
    33613364        # Hostel 2 has only a bed for women.
     
    33753378        self.assertTrue(bed.owner == NOT_OCCUPIED)
    33763379        ac.owner = self.student_id
     3380        self.browser.open(self.acco_path + '/add')
    33773381        self.browser.getControl(name="ac_series").value = sfeseries
    33783382        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']
    33793385        self.browser.getControl("Create bed ticket").click()
    3380         self.assertMatches('...Hall 1, Block A, Room 101, Bed A...',
    3381                           self.browser.contents)
     3386        self.assertTrue('Bed ticket created and bed booked'
     3387            in self.browser.contents)
    33823388        # Bed has been allocated.
    33833389        self.assertTrue(bed.owner == self.student_id)
Note: See TracChangeset for help on using the changeset viewer.