Changeset 6973


Ignore:
Timestamp:
31 Oct 2011, 07:53:13 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement reserved bed switcher.
Change bed_type notation.

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

Legend:

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

    r6970 r6973  
    1717"""
    1818import grok
     19import sys
    1920from time import time
    2021from datetime import date, datetime
     
    152153        hostel = Hostel()
    153154        self.applyData(hostel, **data)
    154         hostel.hostel_id = data['hostel_name'].lower().replace(' ','_')
     155        hostel.hostel_id = data[
     156            'hostel_name'].lower().replace(' ','-').replace('_','-')
    155157        try:
    156158            self.context.addHostel(hostel)
     
    199201    pnav = 5
    200202    taboneactions = ['Save']
    201     tabtwoactions = ['Update beds']
     203    tabtwoactions = ['Update all beds',
     204        'Switch reservation of selected beds',
     205        'Release selected beds']
    202206
    203207    @property
     
    217221        return
    218222
    219     @grok.action('Update beds')
     223    @grok.action('Update all beds')
    220224    def updateBeds(self, **data):
    221225        added, modified = self.context.updateBeds()
     
    223227        self.redirect(self.url(self.context, '@@manage')+'#tab-2')
    224228        return
     229
     230    @grok.action('Switch reservation of selected beds')
     231    def switchReservation(self, **data):
     232        form = self.request.form
     233        if form.has_key('val_id'):
     234            child_id = form['val_id']
     235        else:
     236            self.flash('No item selected.')
     237            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     238            return
     239        if not isinstance(child_id, list):
     240            child_id = [child_id]
     241        switched = []
     242        beds_for_fresh = getattr(self.context,'beds_for_fresh',[])
     243        beds_for_pre = getattr(self.context,'beds_for_pre',[])
     244        beds_for_returning = getattr(self.context,'beds_for_returning',[])
     245        beds_for_final = getattr(self.context,'beds_for_final',[])
     246        for bed_id in child_id:
     247            try:
     248                actual_type = self.context[bed_id].bed_type
     249                sh, sex, bt = actual_type.split('_')
     250                hostel_id, block, room_nr, bed = bed_id.split('_')
     251                if bt == 'reserved':
     252                    bt = 'all'
     253                    if bed in beds_for_fresh:
     254                        bt = 'fr'
     255                    elif bed in beds_for_pre:
     256                        bt = 'pr'
     257                    elif bed in beds_for_final:
     258                        bt = 'fi'
     259                    elif bed in beds_for_returning:
     260                        bt = 're'
     261                    bt = u'%s_%s_%s' % (sh, sex, bt)
     262                else:
     263                    bt = u'%s_%s_reserved' % (sh, sex)
     264                self.context[bed_id].bed_type = bt
     265                switched.append(bed_id)
     266            except:
     267                self.flash('Could not switch %s: %s: %s' % (
     268                        id, sys.exc_info()[0], sys.exc_info()[1]))
     269                self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     270                return
     271        if len(switched):
     272            #import pdb; pdb.set_trace()
     273            self.flash('Successfully switched: %s' % ', '.join(switched))
     274            self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     275        return
     276
     277    @grok.action('Release selected beds')
     278    def releaseBeds(self, **data):
     279        #self.flash('%d released' % released)
     280        self.redirect(self.url(self.context, '@@manage')+'#tab-2')
     281        return
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py

    r6971 r6973  
    8181                        elif bed in beds_for_returning:
    8282                            bt = 're'
    83                         # Hostels with special handling
    84                         if self.special_handling != 'none':
    85                             bt += "_" + self.special_handling
    86                         bt = u'%(sex)s_%(bt)s' % vars()
     83                        bt = u'%s_%s_%s' % (self.special_handling,sex,bt)
    8784                        uid = u'%s_%s_%d_%s' % (self.hostel_id,block,room_nr,bed)
    8885                        if self.has_key(uid):
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py

    r6971 r6973  
    100100        vocabulary = special_handling,
    101101        required = True,
    102         default = u'none',
     102        default = u'regular',
    103103        )
    104104
    105105    reserved = schema.TextLine(
    106         title = u'Reserved Rooms',
     106        title = u'Reserved Beds',
    107107        required = False,
    108         default = u'',
     108        readonly = True,
    109109        )
    110110
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py

    r6972 r6973  
    9494        # Create a hostel
    9595        hostel = Hostel()
    96         hostel.hostel_id = u'hall_x'
     96        hostel.hostel_id = u'hall-x'
    9797        self.app['hostels'][hostel.hostel_id] = hostel
    9898
     
    133133        results = [x for x in results] # Turn results generator into list
    134134        assert len(results) == 1
    135         assert results[0] is self.app['hostels']['hall_x']['xyz']
     135        assert results[0] is self.app['hostels']['hall-x']['xyz']
    136136
    137137class HostelsUITests(HostelsFullSetup):
     
    158158        self.assertTrue('Hostel created' in self.browser.contents)
    159159        #import pdb; pdb.set_trace()
    160         hall = self.app['hostels']['hall_1']
     160        hall = self.app['hostels']['hall-1']
    161161        hall.blocks_for_female = ['A','B']
    162         self.browser.open(self.container_path + '/hall_1')
     162        self.browser.open(self.container_path + '/hall-1')
    163163        expected = '''...<ul id="form.blocks_for_female" ><li>Block A</li>
    164164<li>Block B</li></ul>...'''
    165165        self.assertMatches(expected,self.browser.contents)
    166         self.browser.open(self.container_path + '/hall_1/manage')
     166        self.browser.open(self.container_path + '/hall-1/manage')
    167167        self.browser.getControl(name="form.floors_per_block").value = '4'
    168168        self.browser.getControl("Save").click()
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py

    r6970 r6973  
    3636
    3737special_handling = SimpleWAeUPVocabulary(
    38     ('No special handling','none'),
    39     ('Blocked','blocked'),
     38    ('Regular Hostel','regular'),
     39    ('Blocked Hostel','blocked'),
    4040    ('Postgraduate Hostel','pg'),
    4141    )
Note: See TracChangeset for help on using the changeset viewer.