Changeset 6988 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 2 Nov 2011, 11:23:55 (13 years ago)
- 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 223 223 @grok.action('Update all beds') 224 224 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) 228 230 self.redirect(self.url(self.context, '@@manage')+'#tab-2') 229 231 return … … 243 245 for bed_id in child_id: 244 246 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)) 247 249 except: 248 250 self.flash('Could not switch %s: %s: %s' % ( … … 251 253 return 252 254 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) 254 258 self.redirect(self.url(self.context, '@@manage')+'#tab-2') 255 259 return 256 260 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 50 50 modified_counter = 0 51 51 removed_counter = 0 52 modified_beds = u'' 52 53 53 54 # Remove all empty beds. Occupied beds remain in hostel! … … 96 97 bed.bed_type = bt 97 98 modified_counter += 1 99 modified_beds += '%s ' % uid 98 100 else: 99 101 bed = Bed() … … 104 106 self.addBed(bed) 105 107 added_counter +=1 106 return removed_counter, added_counter, modified_counter 108 return removed_counter, added_counter, modified_counter, modified_beds 107 109 108 110 Hostel = attrs_to_fields(Hostel) … … 120 122 121 123 def switchReservation(self): 122 """Reserves a bed or relases a reservedbed respectively.124 """Reserves a bed or unreserve bed respectively. 123 125 """ 124 126 sh, sex, bt = self.bed_type.split('_') 125 127 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',[])130 128 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',[]) 131 133 bed_string = u'%s_%s_%s' % (block, room_nr, bed) 132 134 if bt == 'reserved': … … 142 144 bt = u'%s_%s_%s' % (sh, sex, bt) 143 145 hostel.beds_reserved.remove(bed_string) 146 message = u'unreserved' 144 147 else: 145 148 bt = u'%s_%s_reserved' % (sh, sex) 146 149 hostel.beds_reserved.append(bed_string) 150 hostel._p_changed = True 151 message = u'reserved' 147 152 self.bed_type = bt 148 return 153 return message 149 154 150 155 def loggerInfo(self, ob_class, comment=None): -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py
r6985 r6988 15 15 ## 16 16 """ 17 Tests for hostels . and their UI components17 Tests for hostels and their UI components. 18 18 """ 19 19 import shutil … … 157 157 self.assertEqual(self.browser.headers['Status'], '200 Ok') 158 158 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) 159 162 hall = self.app['hostels']['hall-1'] 160 163 hall.blocks_for_female = ['A','B'] … … 172 175 self.assertTrue(len(hall.blocks_for_female) == 0) 173 176 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'] 175 180 hall.beds_for_all = ['D','E'] 176 181 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 ()...' 178 183 self.assertMatches(expected,self.browser.contents) 179 184 cat = queryUtility(ICatalog, name='beds_catalog') 180 185 results = cat.searchResults( 181 186 bed_type=('regular_female_all', 'regular_female_all')) 182 #import pdb; pdb.set_trace()183 187 results = [x for x in results] 184 188 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 187 196 ctrl.getControl(value='hall-1_A_101_D').selected = True 188 197 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)' 190 199 in self.browser.contents) 191 assert self.app[ 192 'hostels'][ 193 'hall-1'][ 200 assert self.app['hostels']['hall-1'][ 194 201 '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" />' 196 203 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' 198 206 ctrl = self.browser.getControl(name='val_id') 199 207 ctrl.getControl(value='hall-1_A_101_D').selected = True 200 208 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' 206 213 # Change hostel configuration 207 214 hall.beds_for_all = ['D'] 208 215 self.browser.getControl("Update all beds").click() 209 expected = '... 8 empty beds removed, 6beds added, 0 occupied beds modified...'216 expected = '...10 empty beds removed, 8 beds added, 0 occupied beds modified...' 210 217 self.assertMatches(expected,self.browser.contents) 211 218 results = cat.searchResults( 212 219 bed_type=('regular_female_all', 'regular_female_all')) 213 220 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) 215 232 # Remove entire hostel 216 233 self.browser.open(self.manage_container_path)
Note: See TracChangeset for help on using the changeset viewer.