Ignore:
Timestamp:
2 Nov 2011, 11:23:55 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement logging for reservation switch.

Fix switchReservation.

Improve testing.

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

Legend:

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

    r6978 r6988  
    223223    @grok.action('Update all beds')
    224224    def updateBeds(self, **data):
    225         removed, added, modified = self.context.updateBeds()
    226         self.flash('%d empty beds removed, %d beds added, %d occupied beds modified' % (
    227             removed, added, modified))
     225        removed, added, modified, modified_beds = self.context.updateBeds()
     226        message = '%d empty beds removed, %d beds added, %d occupied beds modified (%s)' % (
     227            removed, added, modified, modified_beds)
     228        self.flash(message)
     229        write_log_message(self, message)
    228230        self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    229231        return
     
    243245        for bed_id in child_id:
    244246            try:
    245                 self.context[bed_id].switchReservation()
    246                 switched.append(bed_id)
     247                message = self.context[bed_id].switchReservation()
     248                switched.append('%s (%s)' % (bed_id,message))
    247249            except:
    248250                self.flash('Could not switch %s: %s: %s' % (
     
    251253                return
    252254        if len(switched):
    253             self.flash('Successfully switched beds: %s' % ', '.join(switched))
     255            message = ', '.join(switched)
     256            self.flash('Successfully switched beds: %s' % message)
     257            write_log_message(self, 'switched: % s' % message)
    254258            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    255259        return
    256260
    257     @grok.action('Release selected beds')
    258     def releaseBeds(self, **data):
    259         #self.flash('%d released' % released)
    260         self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    261         return
     261    # Needed for removing students from beds
     262    #@grok.action('Release selected beds')
     263    #def releaseBeds(self, **data):
     264    #    #self.flash('%d released' % released)
     265    #    self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     266    #    return
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py

    r6978 r6988  
    5050        modified_counter = 0
    5151        removed_counter = 0
     52        modified_beds = u''
    5253
    5354        # Remove all empty beds. Occupied beds remain in hostel!
     
    9697                                bed.bed_type = bt
    9798                                modified_counter += 1
     99                                modified_beds += '%s ' % uid
    98100                        else:
    99101                            bed = Bed()
     
    104106                            self.addBed(bed)
    105107                            added_counter +=1
    106         return removed_counter, added_counter, modified_counter
     108        return removed_counter, added_counter, modified_counter, modified_beds
    107109
    108110Hostel = attrs_to_fields(Hostel)
     
    120122
    121123    def switchReservation(self):
    122         """Reserves a bed or relases a reserved bed respectively.
     124        """Reserves a bed or unreserve bed respectively.
    123125        """
    124126        sh, sex, bt = self.bed_type.split('_')
    125127        hostel_id, block, room_nr, bed = self.getBedCoordinates()
    126         beds_for_fresh = getattr(self,'beds_for_fresh',[])
    127         beds_for_pre = getattr(self,'beds_for_pre',[])
    128         beds_for_returning = getattr(self,'beds_for_returning',[])
    129         beds_for_final = getattr(self,'beds_for_final',[])
    130128        hostel = self.__parent__
     129        beds_for_fresh = getattr(hostel,'beds_for_fresh',[])
     130        beds_for_pre = getattr(hostel,'beds_for_pre',[])
     131        beds_for_returning = getattr(hostel,'beds_for_returning',[])
     132        beds_for_final = getattr(hostel,'beds_for_final',[])
    131133        bed_string = u'%s_%s_%s' % (block, room_nr, bed)
    132134        if bt == 'reserved':
     
    142144            bt = u'%s_%s_%s' % (sh, sex, bt)
    143145            hostel.beds_reserved.remove(bed_string)
     146            message = u'unreserved'
    144147        else:
    145148            bt = u'%s_%s_reserved' % (sh, sex)
    146149            hostel.beds_reserved.append(bed_string)
     150            hostel._p_changed = True
     151            message = u'reserved'
    147152        self.bed_type = bt
    148         return
     153        return message
    149154
    150155    def loggerInfo(self, ob_class, comment=None):
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py

    r6985 r6988  
    1515##
    1616"""
    17 Tests for hostels. and their UI components
     17Tests for hostels and their UI components.
    1818"""
    1919import shutil
     
    157157        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    158158        self.assertTrue('Hostel created' in self.browser.contents)
     159        self.browser.open(self.container_path + '/addhostel')
     160        self.browser.getControl("Create hostel").click()
     161        self.assertTrue('The hostel already exists' in self.browser.contents)
    159162        hall = self.app['hostels']['hall-1']
    160163        hall.blocks_for_female = ['A','B']
     
    172175        self.assertTrue(len(hall.blocks_for_female) == 0)
    173176        hall.blocks_for_female = ['A','B']
    174         hall.beds_for_fresh = ['A','B']
     177        hall.beds_for_fresh = ['A']
     178        hall.beds_for_returning = ['B']
     179        hall.beds_for_final = ['C']
    175180        hall.beds_for_all = ['D','E']
    176181        self.browser.getControl("Update all beds").click()
    177         expected = '...0 empty beds removed, 8 beds added, 0 occupied beds modified...'
     182        expected = '...0 empty beds removed, 10 beds added, 0 occupied beds modified ()...'
    178183        self.assertMatches(expected,self.browser.contents)
    179184        cat = queryUtility(ICatalog, name='beds_catalog')
    180185        results = cat.searchResults(
    181186            bed_type=('regular_female_all', 'regular_female_all'))
    182         #import pdb; pdb.set_trace()
    183187        results = [x for x in results]
    184188        assert len(results) == 4
    185         # Set bed reserved
    186         ctrl = self.browser.getControl(name='val_id')
     189        # Reserve bed
     190        self.browser.getControl("Switch reservation", index=0).click()
     191        self.assertTrue('No item selected' in self.browser.contents)
     192        ctrl = self.browser.getControl(name='val_id')
     193        ctrl.getControl(value='hall-1_A_101_A').selected = True
     194        ctrl.getControl(value='hall-1_A_101_B').selected = True
     195        ctrl.getControl(value='hall-1_A_101_C').selected = True
    187196        ctrl.getControl(value='hall-1_A_101_D').selected = True
    188197        self.browser.getControl("Switch reservation", index=0).click()
    189         self.assertTrue('Successfully switched beds: hall-1_A_101_D'
     198        self.assertTrue('Successfully switched beds: hall-1_A_101_A (reserved)'
    190199            in self.browser.contents)
    191         assert self.app[
    192             'hostels'][
    193             'hall-1'][
     200        assert self.app['hostels']['hall-1'][
    194201            'hall-1_A_101_D'].bed_type == 'regular_female_reserved'
    195         expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_D"  />'
     202        expected = 'name="form.beds_reserved.0." size="20" type="text" value="A_101_A"  />'
    196203        self.assertTrue(expected in self.browser.contents)
    197         # Release bed
     204        # Provoke exception
     205        self.app['hostels']['hall-1']['hall-1_A_101_D'].bed_type = u'nonsense'
    198206        ctrl = self.browser.getControl(name='val_id')
    199207        ctrl.getControl(value='hall-1_A_101_D').selected = True
    200208        self.browser.getControl("Switch reservation", index=0).click()
    201         assert self.app[
    202             'hostels'][
    203             'hall-1'][
    204             'hall-1_A_101_D'].bed_type == 'regular_female_all'
    205         self.assertFalse(expected in self.browser.contents)
     209        self.assertMatches(
     210            '...need more than 1 value to unpack...', self.browser.contents)
     211        self.app['hostels']['hall-1'][
     212            'hall-1_A_101_D'].bed_type = u'regular_female_reserved'
    206213        # Change hostel configuration
    207214        hall.beds_for_all = ['D']
    208215        self.browser.getControl("Update all beds").click()
    209         expected = '...8 empty beds removed, 6 beds added, 0 occupied beds modified...'
     216        expected = '...10 empty beds removed, 8 beds added, 0 occupied beds modified...'
    210217        self.assertMatches(expected,self.browser.contents)
    211218        results = cat.searchResults(
    212219            bed_type=('regular_female_all', 'regular_female_all'))
    213220        results = [x for x in results]
    214         assert len(results) == 2
     221        assert len(results) == 1
     222        # Unreserve bed
     223        ctrl = self.browser.getControl(name='val_id')
     224        ctrl.getControl(value='hall-1_A_101_A').selected = True
     225        ctrl.getControl(value='hall-1_A_101_B').selected = True
     226        ctrl.getControl(value='hall-1_A_101_C').selected = True
     227        ctrl.getControl(value='hall-1_A_101_D').selected = True
     228        self.browser.getControl("Switch reservation", index=0).click()
     229        assert self.app['hostels']['hall-1'][
     230            'hall-1_A_101_D'].bed_type == 'regular_female_all'
     231        self.assertFalse(expected in self.browser.contents)
    215232        # Remove entire hostel
    216233        self.browser.open(self.manage_container_path)
Note: See TracChangeset for help on using the changeset viewer.