Changeset 6997 for main/waeup.sirp/trunk


Ignore:
Timestamp:
4 Nov 2011, 17:32:02 (13 years ago)
Author:
Henrik Bettermann
Message:

Don't use access code if no bed is found. This is in contrast to the Uniben practice.

File:
1 edited

Legend:

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

    r6996 r6997  
    5353from waeup.sirp.browser.resources import toggleall
    5454from waeup.sirp.authentication import get_principal_role_manager
     55from waeup.sirp.hostels.hostel import NOT_OCCUPIED
    5556
    5657def write_log_message(view, message):
     
    11071108            self.flash('Activation code is invalid.')
    11081109            return
     1110        # Search a bed and exit if no bed is found
     1111        cat = queryUtility(ICatalog, name='beds_catalog', default=None)
     1112        entries = cat.searchResults(
     1113            bed_type=(acc_details['bt'],acc_details['bt']))
     1114        available_beds = [
     1115            entry for entry in entries if entry.owner == NOT_OCCUPIED]
     1116        if not available_beds:
     1117            self.flash('There is no free bed in your category %s.'
     1118                        % acc_details['bt'])
     1119            return
    11091120        # Mark pin as used (this also fires a pin related transition)
    11101121        if code.state == USED:
     
    11191130                self.flash('You are not the owner of this access code.')
    11201131                return
     1132        # Create bed ticket and book bed
    11211133        bedticket = createObject(u'waeup.BedTicket')
    11221134        bedticket.booking_code = pin
    11231135        bedticket.booking_session = acc_details['booking_session']
    11241136        bedticket.bed_type = acc_details['bt']
    1125         # Search and book bed
    1126         cat = queryUtility(ICatalog, name='beds_catalog', default=None)
    1127         entries = cat.searchResults(
    1128             bed_type=(bedticket.bed_type,bedticket.bed_type))
    1129         bed = [entry for entry in entries if entry.owner == NOT_OCCUPIED][0] # first bed found
     1137        bed = available_beds[0] # first bed found
    11301138        bed.bookBed(student.student_id)
    11311139        bedticket.bed = bed # maybe wo don't need the bed object itself
Note: See TracChangeset for help on using the changeset viewer.