Ignore:
Timestamp:
10 Nov 2011, 18:56:18 (13 years ago)
Author:
Henrik Bettermann
Message:

Much more logic for bed allocation, bed release.

Implement student relocation.

File:
1 edited

Legend:

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

    r7061 r7068  
    186186                self.flash('Empty search string.')
    187187            return
     188        if self.searchtype == 'current_session':
     189            self.searchterm = int(self.searchterm)
    188190        self.hitlist = search(query=self.searchterm,
    189191            searchtype=self.searchtype, view=self)
     
    11781180        deleted = []
    11791181        for id in child_id:
    1180             try:
    1181                 del self.context[id]
    1182                 deleted.append(id)
    1183             except:
    1184                 self.flash('Could not delete %s: %s: %s' % (
    1185                         id, sys.exc_info()[0], sys.exc_info()[1]))
     1182            del self.context[id]
     1183            deleted.append(id)
    11861184        if len(deleted):
    11871185            self.flash('Successfully removed: %s' % ', '.join(deleted))
     
    12951293        coordinates = bed.getBedCoordinates()[1:]
    12961294        block, room_nr, bed_nr = coordinates
    1297         bedticket.bed_coordinates = '%s, Block %s, Room %s, Bed %s' % (
    1298             hall_title, block, room_nr, bed_nr)
     1295        bedticket.bed_coordinates = '%s, Block %s, Room %s, Bed %s (%s)' % (
     1296            hall_title, block, room_nr, bed_nr, bed.bed_type)
    12991297        key = str(acc_details['booking_session'])
    13001298        self.context[key] = bedticket
     
    13811379        student = self.context.getStudent()
    13821380        acc_details  = self.getAccommodationDetails(student)
     1381        if self.context.bed != None and \
     1382              'reserved' in self.context.bed.bed_type:
     1383            self.flash("Students in reserved beds can't be relocated.")
     1384            self.redirect(self.url(self.context))
     1385            return
    13831386        if acc_details['bt'] == self.context.bed_type and \
     1387                self.context.bed != None and \
    13841388                self.context.bed.bed_type == self.context.bed_type:
    1385             self.flash("Bed category hasn't changed. Student can't be relocated.")
    1386             return
    1387         # Search a bed and exit if no bed is found
     1389            self.flash("Student can't be relocated.")
     1390            self.redirect(self.url(self.context))
     1391            return
     1392        # Search a bed
    13881393        cat = queryUtility(ICatalog, name='beds_catalog', default=None)
    13891394        entries = cat.searchResults(
    1390             bed_type=(acc_details['bt'],acc_details['bt']))
    1391         available_beds = [
    1392             entry for entry in entries if entry.owner == NOT_OCCUPIED]
    1393         if not available_beds:
    1394             self.flash('There is no free bed in your category %s.'
    1395                         % acc_details['bt'])
    1396             return
    1397         #entries = cat.searchResults(
    1398         #    owner=(student.student_id,student.student_id))
    1399         # Rlease old bed
    1400         try:
    1401             allocated_bed = self.context.bed
    1402             allocated_bed.owner = NOT_OCCUPIED
    1403             notify(grok.ObjectModifiedEvent(allocated_bed))
    1404         except AttributeError:
    1405             # Cannot happen but anyway...
    1406             pass
     1395            owner=(student.student_id,student.student_id))
     1396        if len(entries) and self.context.bed == None:
     1397            # If booking has been cancelled but other bed space has been
     1398            # manually allocated after cancellation use this bed
     1399            new_bed = [entry for entry in entries][0]
     1400        else:
     1401            # Search for other available beds
     1402            entries = cat.searchResults(
     1403                bed_type=(acc_details['bt'],acc_details['bt']))
     1404            available_beds = [
     1405                entry for entry in entries if entry.owner == NOT_OCCUPIED]
     1406            if available_beds:
     1407                new_bed = self.selectBed(available_beds)
     1408                new_bed.bookBed(student.student_id)
     1409            else:
     1410                self.flash('There is no free bed in your category %s.'
     1411                            % acc_details['bt'])
     1412                self.redirect(self.url(self.context))
     1413                return
     1414        # Rlease old bed if exists
     1415        if self.context.bed != None:
     1416            self.context.bed.owner = NOT_OCCUPIED
     1417            notify(grok.ObjectModifiedEvent(self.context.bed))
    14071418        # Alocate new bed
    14081419        self.context.bed_type = acc_details['bt']
    1409         bed = self.selectBed(available_beds)
    1410         bed.bookBed(student.student_id)
    1411         self.context.bed = bed
    1412         hall_title = bed.__parent__.hostel_name
    1413         coordinates = bed.getBedCoordinates()[1:]
     1420        self.context.bed = new_bed
     1421        hall_title = new_bed.__parent__.hostel_name
     1422        coordinates = new_bed.getBedCoordinates()[1:]
    14141423        block, room_nr, bed_nr = coordinates
    1415         self.context.bed_coordinates = '%s, Block %s, Room %s, Bed %s' % (
    1416             hall_title, block, room_nr, bed_nr)
    1417         self.flash('Student relocated and new bed booked: %s'
    1418             % self.context.bed_coordinates)
     1424        self.context.bed_coordinates = '%s, Block %s, Room %s, Bed %s (%s)' % (
     1425            hall_title, block, room_nr, bed_nr, new_bed.bed_type)
     1426        self.flash('Student relocated: %s' % self.context.bed_coordinates)
    14191427        self.redirect(self.url(self.context))
    14201428        return
    14211429
    14221430    def render(self):
    1423         self.redirect(self.url(self.context, '@@index'))
     1431        #self.redirect(self.url(self.context, '@@index'))
    14241432        return
    14251433
Note: See TracChangeset for help on using the changeset viewer.