- Timestamp:
- 31 Oct 2011, 07:53:13 (13 years ago)
- 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 17 17 """ 18 18 import grok 19 import sys 19 20 from time import time 20 21 from datetime import date, datetime … … 152 153 hostel = Hostel() 153 154 self.applyData(hostel, **data) 154 hostel.hostel_id = data['hostel_name'].lower().replace(' ','_') 155 hostel.hostel_id = data[ 156 'hostel_name'].lower().replace(' ','-').replace('_','-') 155 157 try: 156 158 self.context.addHostel(hostel) … … 199 201 pnav = 5 200 202 taboneactions = ['Save'] 201 tabtwoactions = ['Update beds'] 203 tabtwoactions = ['Update all beds', 204 'Switch reservation of selected beds', 205 'Release selected beds'] 202 206 203 207 @property … … 217 221 return 218 222 219 @grok.action('Update beds')223 @grok.action('Update all beds') 220 224 def updateBeds(self, **data): 221 225 added, modified = self.context.updateBeds() … … 223 227 self.redirect(self.url(self.context, '@@manage')+'#tab-2') 224 228 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 81 81 elif bed in beds_for_returning: 82 82 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) 87 84 uid = u'%s_%s_%d_%s' % (self.hostel_id,block,room_nr,bed) 88 85 if self.has_key(uid): -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py
r6971 r6973 100 100 vocabulary = special_handling, 101 101 required = True, 102 default = u' none',102 default = u'regular', 103 103 ) 104 104 105 105 reserved = schema.TextLine( 106 title = u'Reserved Rooms',106 title = u'Reserved Beds', 107 107 required = False, 108 default = u'',108 readonly = True, 109 109 ) 110 110 -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py
r6972 r6973 94 94 # Create a hostel 95 95 hostel = Hostel() 96 hostel.hostel_id = u'hall _x'96 hostel.hostel_id = u'hall-x' 97 97 self.app['hostels'][hostel.hostel_id] = hostel 98 98 … … 133 133 results = [x for x in results] # Turn results generator into list 134 134 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'] 136 136 137 137 class HostelsUITests(HostelsFullSetup): … … 158 158 self.assertTrue('Hostel created' in self.browser.contents) 159 159 #import pdb; pdb.set_trace() 160 hall = self.app['hostels']['hall _1']160 hall = self.app['hostels']['hall-1'] 161 161 hall.blocks_for_female = ['A','B'] 162 self.browser.open(self.container_path + '/hall _1')162 self.browser.open(self.container_path + '/hall-1') 163 163 expected = '''...<ul id="form.blocks_for_female" ><li>Block A</li> 164 164 <li>Block B</li></ul>...''' 165 165 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') 167 167 self.browser.getControl(name="form.floors_per_block").value = '4' 168 168 self.browser.getControl("Save").click() -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py
r6970 r6973 36 36 37 37 special_handling = SimpleWAeUPVocabulary( 38 (' No special handling','none'),39 ('Blocked ','blocked'),38 ('Regular Hostel','regular'), 39 ('Blocked Hostel','blocked'), 40 40 ('Postgraduate Hostel','pg'), 41 41 )
Note: See TracChangeset for help on using the changeset viewer.