Changeset 9197
- Timestamp:
- 18 Sep 2012, 16:24:21 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/hostels
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/hostels/browser.py
r8685 r9197 130 130 form_fields = grok.AutoFields(IHostelsContainer) 131 131 taboneactions = [_('Save')] 132 tabtwoactions = [_('Add hostel'), _('Remove selected')] 132 tabtwoactions = [_('Add hostel'), 133 _('Clear all hostels'), 134 _('Remove selected')] 133 135 134 136 def update(self): … … 164 166 return 165 167 168 @jsaction(_('Clear all hostels')) 169 def clearHostels(self, **data): 170 self.context.clearAllHostels() 171 self.flash(_('All hostels cleared.')) 172 write_log_message(self, 'all hostels cleared') 173 self.redirect(self.url(self.context, '@@manage')+'?tab2') 174 return 175 166 176 @action(_('Save'), style='primary') 167 177 def save(self, **data): … … 232 242 tabtwoactions = [_('Update all beds'), 233 243 _('Switch reservation of selected beds'), 234 _('Release selected beds')] 244 _('Release selected beds'), 245 _('Clear hostel')] 235 246 not_occupied = NOT_OCCUPIED 236 247 … … 243 254 tabs.need() 244 255 datatable.need() 256 warning.need() 245 257 self.tab1 = self.tab2 = '' 246 258 qs = self.request.get('QUERY_STRING', '') … … 327 339 return 328 340 341 @jsaction(_('Clear hostel')) 342 def clearHostel(self, **data): 343 self.context.clearHostel() 344 self.flash(_('Hostel cleared.')) 345 write_log_message(self, 'cleared') 346 self.redirect(self.url(self.context, '@@manage')+'?tab2') 347 return 348 329 349 class BedManageFormPage(KofaEditFormPage): 330 350 """ View to edit bed data -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/container.py
r8686 r9197 51 51 return 52 52 53 def clearAllHostels(self): 54 """Clear all hostels. 55 """ 56 for hostel in self.values(): 57 hostel.clearHostel() 58 return 59 53 60 logger_name = 'waeup.kofa.${sitename}.hostels' 54 61 logger_filename = 'hostels.log' -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py
r9196 r9197 51 51 52 52 def clearHostel(self): 53 """Remove all beds. 54 55 This methods is pretty fast and optimized. Use it instead of 56 removing all items manually yourself. 57 """ 58 # This internal function is implemented in C and thus much 59 # faster as we could do it in pure Python. 60 self._SampleContainer__data.clear() 61 # The length attribute is 'lazy'. See `zope.container` for details. 62 # This way we make sure, the next time len() is called, it returns 63 # the real value and not a cached one. 64 del self.__dict__['_BTreeContainer__len'] 53 """Remove all beds 54 """ 55 keys = [i for i in self.keys()] # create deep copy 56 for bed in keys: 57 del self[bed] 58 return 65 59 66 60 def addBed(self, bed): -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/interfaces.py
r9196 r9197 57 57 default = [], 58 58 ) 59 60 def clearAllHostels(): 61 """Clear all hostels. 62 """ 59 63 60 64 class IHostel(IKofaObject): -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py
r9196 r9197 19 19 Tests for hostels and their UI components. 20 20 """ 21 import os 21 22 import shutil 22 23 import tempfile … … 349 350 results = [x for x in results] 350 351 assert len(results) == 0 352 353 def test_clear_hostels(self): 354 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 355 self.browser.open(self.container_path) 356 self.browser.getLink("Manage accommodation").click() 357 self.browser.getControl("Add hostel").click() 358 self.browser.getControl("Create hostel").click() 359 hall = self.app['hostels']['hall-1'] 360 hall.blocks_for_female = ['A','B'] 361 hall.rooms_per_floor = 1 362 hall.beds_for_fresh = ['A'] 363 hall.beds_for_returning = ['B'] 364 hall.beds_for_final = ['C'] 365 hall.beds_for_all = ['D','E'] 366 self.browser.open(self.container_path + '/hall-1/manage') 367 self.browser.getControl("Update all beds").click() 368 cat = queryUtility(ICatalog, name='beds_catalog') 369 results = cat.searchResults(bed_type=(None, None)) 370 self.assertEqual(len(results), 11) 371 self.browser.getControl("Clear hostel").click() 372 self.assertEqual(len(self.app['hostels']['hall-1']), 0) 373 # Only the bed in hall-x remains in the catalog. 374 results = cat.searchResults(bed_type=(None, None)) 375 self.assertEqual(len(results), 1) 376 # We can clear all hostels at the same time. 377 self.browser.open(self.manage_container_path) 378 self.browser.getControl("Clear all hostels").click() 379 results = cat.searchResults(bed_type=(None, None)) 380 self.assertEqual(len(results), 0) 381 # Both actions have been logged. 382 logfile = os.path.join( 383 self.app['datacenter'].storage, 'logs', 'hostels.log') 384 logcontent = open(logfile).read() 385 self.assertTrue('INFO - zope.mgr - hostels.browser.HostelManageFormPage' 386 ' - hall-1 - cleared' in logcontent) 387 self.assertTrue('zope.mgr - hostels.browser.HostelsContainerManagePage' 388 ' - hostels - all hostels cleared' in logcontent)
Note: See TracChangeset for help on using the changeset viewer.