Changeset 7042 for main


Ignore:
Timestamp:
8 Nov 2011, 21:50:31 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement releaseBed method and releaseBeds action (test will follow).

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
3 edited

Legend:

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

    r6996 r7042  
    260260            message = ', '.join(switched)
    261261            self.flash('Successfully switched beds: %s' % message)
    262             write_log_message(self, 'switched: % s' % message)
    263             self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    264         return
    265 
    266     # Needed for removing students from beds
    267     #@grok.action('Release selected beds')
    268     #def releaseBeds(self, **data):
    269     #    #self.flash('%d released' % released)
    270     #    self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    271     #    return
     262            write_log_message(self, 'switched: %s' % message)
     263            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     264        return
     265
     266    @grok.action('Release selected beds')
     267    def releaseBeds(self, **data):
     268        form = self.request.form
     269        if form.has_key('val_id'):
     270            child_id = form['val_id']
     271        else:
     272            self.flash('No item selected.')
     273            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     274            return
     275        if not isinstance(child_id, list):
     276            child_id = [child_id]
     277        released = []
     278        for bed_id in child_id:
     279            try:
     280                message = self.context[bed_id].releaseBed()
     281                released.append('%s (%s)' % (bed_id,message))
     282            except:
     283                self.flash('Could not release %s: %s: %s' % (
     284                        id, sys.exc_info()[0], sys.exc_info()[1]))
     285                self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     286                return
     287        if len(released):
     288            message = ', '.join(released)
     289            self.flash('Successfully released beds: %s' % message)
     290            write_log_message(self, 'released: %s' % message)
     291            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     292        return
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py

    r7006 r7042  
    177177        return message
    178178
     179    def releaseBed(self):
     180        if self.owner == NOT_OCCUPIED:
     181            return u'not occupied'
     182        else:
     183            old_owner = self.owner
     184            self.owner = NOT_OCCUPIED
     185            notify(grok.ObjectModifiedEvent(self))
     186            accommodation_session = grok.getSite()[
     187                'configuration'].accommodation_session
     188            try:
     189            #import pdb; pdb.set_trace()
     190                bedticket = grok.getSite()['students'][old_owner][
     191                              'accommodation'][str(accommodation_session)]
     192            except KeyError:
     193                return '%s without bed ticket' % old_owner
     194            bedticket.bed = None
     195            timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
     196            bedticket.bed_coordinates = u'-- booking cancelled on %s --' % timestamp
     197            return old_owner
     198
    179199    def loggerInfo(self, ob_class, comment=None):
    180200        target = self.__name__
     
    188208    of the bed is cleared (set to NOT_OCCUPIED).
    189209    """
    190     allocated_bed = bedticket.bed
    191     allocated_bed.owner = NOT_OCCUPIED
    192     notify(grok.ObjectModifiedEvent(allocated_bed))
     210    if bedticket.bed:
     211        allocated_bed = bedticket.bed
     212        allocated_bed.owner = NOT_OCCUPIED
     213        notify(grok.ObjectModifiedEvent(allocated_bed))
     214    else:
     215        pass
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7029 r7042  
    13811381            owner=(student.student_id,student.student_id))
    13821382        # Rlease old bed
    1383         allocated_bed = self.context.bed
    1384         allocated_bed.owner = NOT_OCCUPIED
    1385         notify(grok.ObjectModifiedEvent(allocated_bed))
     1383        try:
     1384            allocated_bed = self.context.bed
     1385            allocated_bed.owner = NOT_OCCUPIED
     1386            notify(grok.ObjectModifiedEvent(allocated_bed))
     1387        except AttributeError:
     1388            # Cannot happen but anyway...
     1389            pass
    13861390        # Alocate new bed
    13871391        self.context.bed_type = acc_details['bt']
Note: See TracChangeset for help on using the changeset viewer.