Changeset 17412 for main/waeup.kofa
- Timestamp:
- 17 May 2023, 18:21:10 (18 months ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r17411 r17412 4 4 1.8.2.dev0 (unreleased) 5 5 ======================= 6 7 * Add `ReleaseExpiredAllocationsPage2` which allows to release unpaid beds 8 in single hostels. 6 9 7 10 * Show matric number on `TranscriptOfficerLandingPage`. -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/browser.py
r17313 r17412 135 135 @property 136 136 def target_url(self): 137 if self.target and self.context.allocation_expiration:137 if self.target and grok.getSite()['hostels'].allocation_expiration: 138 138 return self.view.url(self.view.context, self.target) 139 139 return … … 146 146 "booking if maintenance fee is not " + \ 147 147 "paid.'") 148 msg = _(msg, mapping={'a': self.context.allocation_expiration,})148 msg = _(msg, mapping={'a': grok.getSite()['hostels'].allocation_expiration,}) 149 149 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 150 150 return "return window.confirm(%s);" % translate( … … 218 218 219 219 def update(self): 220 n = self.context.allocation_expiration220 n = grok.getSite()['hostels'].allocation_expiration 221 221 if not n: 222 222 self.flash( … … 250 250 return 251 251 252 class ReleaseExpiredAllocationsPage2(ReleaseExpiredAllocationsPage): 253 """Release all expired allocated beds in a single hostel. 254 """ 255 grok.context(IHostel) 256 grok.name('releaseexpired2') 257 252 258 class HostelsStatisticsPage(KofaDisplayFormPage): 253 259 """Some statistics about beds in hostels. … … 300 306 def label(self): 301 307 return self.context.hostel_name 308 309 class ReleaseExpiredAllocationsActionButton2(ReleaseExpiredAllocationsActionButton): 310 grok.order(2) 311 grok.context(IHostel) 312 grok.view(HostelDisplayFormPage) 313 target = 'releaseexpired2' 314 text = _('Release expired bed space allocations in this hostel') 302 315 303 316 class HostelManageActionButton(ManageActionButton): -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py
r17313 r17412 21 21 import grok 22 22 from zope.event import notify 23 from zope.component import getUtility, createObject23 from zope.component import queryUtility, getUtility, createObject 24 24 from zope.component.interfaces import IFactory, ComponentLookupError 25 25 from zope.catalog.interfaces import ICatalog … … 138 138 return removed_counter, added_counter, modified_counter, modified_beds 139 139 140 def releaseExpiredAllocations(self, n=7): 141 """Release bed in hostel if bed allocation has expired. Allocation expires 142 after `n` days if maintenance fee has not been paid. 143 """ 144 cat = queryUtility(ICatalog, name='beds_catalog') 145 results = cat.searchResults(bed_type=(None,None)) 146 released = [] 147 for bed in results: 148 if not bed.bed_id.startswith(self.hostel_id): 149 continue 150 student_id = bed.releaseBedIfMaintenanceNotPaid(n=n) 151 if student_id: 152 released.append('%s (%s)' % (bed.bed_id,student_id)) 153 return released 154 140 155 def writeLogMessage(self, view, message): 141 156 ob_class = view.__implemented__.__name__.replace('waeup.kofa.','') -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py
r17313 r17412 164 164 # Create a bed 165 165 bed = Bed() 166 bed.bed_id = u'hall _block_room_bed'166 bed.bed_id = u'hall-x_block_room_bed' 167 167 bed.bed_number = 1 168 168 bed.bed_type = u'regular_male_fr' … … 191 191 layer = FunctionalLayer 192 192 193 def test_release_expired_allocations (self):193 def test_release_expired_allocations_portalwide(self): 194 194 self.app['hostels'].allocation_expiration = 7 195 195 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') … … 200 200 self.student['accommodation'].addBedTicket(bedticket) 201 201 self.app[ 202 'hostels']['hall-x']['hall _block_room_bed'].owner = self.student_id202 'hostels']['hall-x']['hall-x_block_room_bed'].owner = self.student_id 203 203 notify(grok.ObjectModifiedEvent( 204 self.app['hostels']['hall-x']['hall _block_room_bed']))205 self.assertEqual( 206 self.app['hostels']['hall-x']['hall _block_room_bed'].bed_type,204 self.app['hostels']['hall-x']['hall-x_block_room_bed'])) 205 self.assertEqual( 206 self.app['hostels']['hall-x']['hall-x_block_room_bed'].bed_type, 207 207 'regular_male_fr') 208 208 results = cat.searchResults(owner=(self.student_id, self.student_id)) … … 218 218 self.browser.open(self.container_path + '/releaseexpired') 219 219 self.assertTrue( 220 'Successfully released beds: hall _block_room_bed (K1000000)'220 'Successfully released beds: hall-x_block_room_bed (K1000000)' 221 221 in self.browser.contents) 222 222 results = cat.searchResults(owner=(self.student_id, self.student_id)) … … 226 226 # The owner has been removed and the bed reserved. 227 227 self.assertEqual( 228 self.app['hostels']['hall-x']['hall _block_room_bed'].owner,228 self.app['hostels']['hall-x']['hall-x_block_room_bed'].owner, 229 229 NOT_OCCUPIED) 230 230 self.assertEqual( 231 self.app['hostels']['hall-x']['hall _block_room_bed'].bed_type,231 self.app['hostels']['hall-x']['hall-x_block_room_bed'].bed_type, 232 232 'regular_male_reserved') 233 233 # Accommodation session can't be changed if hostels are not empty. … … 242 242 self.assertTrue( 243 243 'hostels.browser.ReleaseExpiredAllocationsPage - hostels - ' 244 'released: hall_block_room_bed (K1000000)' 244 'released: hall-x_block_room_bed (K1000000)' 245 in logcontent) 246 return 247 248 def test_release_expired_allocations_in_hostel(self): 249 self.app['hostels'].allocation_expiration = 7 250 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 251 cat = queryUtility(ICatalog, name='beds_catalog') 252 bedticket = BedTicket() 253 bedticket.booking_session = 2004 254 bedticket.bed_coordinates = u'anything' 255 delta = timedelta(days=10) 256 bedticket.booking_date = datetime.utcnow() - delta 257 self.student['accommodation'].addBedTicket(bedticket) 258 self.app[ 259 'hostels']['hall-x']['hall-x_block_room_bed'].owner = self.student_id 260 notify(grok.ObjectModifiedEvent( 261 self.app['hostels']['hall-x']['hall-x_block_room_bed'])) 262 self.assertEqual( 263 self.app['hostels']['hall-x']['hall-x_block_room_bed'].bed_type, 264 'regular_male_fr') 265 results = cat.searchResults(owner=(self.student_id, self.student_id)) 266 self.assertEqual(len(results), 1) 267 grok.getSite()['configuration'].maintmode_enabled_by = u'any_id' 268 self.browser.open(self.container_path + '/hall-x/releaseexpired2') 269 self.assertTrue( 270 'Successfully released beds: hall-x_block_room_bed (K1000000)' 271 in self.browser.contents) 272 results = cat.searchResults(owner=(self.student_id, self.student_id)) 273 self.assertEqual(len(results), 0) 274 self.assertMatches(bedticket.display_coordinates, 275 '-- booking expired (2015-10-14 08:35:38 UTC) --') 276 # The owner has been removed and the bed reserved. 277 self.assertEqual( 278 self.app['hostels']['hall-x']['hall-x_block_room_bed'].owner, 279 NOT_OCCUPIED) 280 self.assertEqual( 281 self.app['hostels']['hall-x']['hall-x_block_room_bed'].bed_type, 282 'regular_male_reserved') 283 # Releasing is logged. 284 logcontent = open(self.logfile).read() 285 self.assertTrue( 286 'hostels.browser.ReleaseExpiredAllocationsPage2 - hall-x - ' 287 'released: hall-x_block_room_bed (K1000000)' 245 288 in logcontent) 246 289 return … … 249 292 utils = getUtility(IHostelsUtils) 250 293 self.app['hostels']['hall-x'][ 251 'hall _block_room_bed'].owner = NOT_OCCUPIED294 'hall-x_block_room_bed'].owner = NOT_OCCUPIED 252 295 notify(grok.ObjectModifiedEvent( 253 self.app['hostels']['hall-x']['hall _block_room_bed']))296 self.app['hostels']['hall-x']['hall-x_block_room_bed'])) 254 297 stats = utils.getBedStatistics() 255 298 self.assertEqual(stats, … … 266 309 ) 267 310 self.app[ 268 'hostels']['hall-x']['hall _block_room_bed'].owner = self.student_id311 'hostels']['hall-x']['hall-x_block_room_bed'].owner = self.student_id 269 312 notify(grok.ObjectModifiedEvent( 270 self.app['hostels']['hall-x']['hall _block_room_bed']))313 self.app['hostels']['hall-x']['hall-x_block_room_bed'])) 271 314 stats = utils.getBedStatistics() 272 315 self.assertEqual(stats, … … 299 342 results = [x for x in results] # Turn results generator into list 300 343 assert len(results) == 1 301 assert results[0] is self.app['hostels']['hall-x']['hall _block_room_bed']344 assert results[0] is self.app['hostels']['hall-x']['hall-x_block_room_bed'] 302 345 303 346 def test_search_by_owner(self): 304 347 # We can find a certain bed 305 myobj = self.app['hostels']['hall-x']['hall _block_room_bed']348 myobj = self.app['hostels']['hall-x']['hall-x_block_room_bed'] 306 349 myobj.owner = u'abc' 307 350 notify(grok.ObjectModifiedEvent(myobj)) … … 310 353 results = [x for x in results] # Turn results generator into list 311 354 assert len(results) == 1 312 assert results[0] is self.app['hostels']['hall-x']['hall _block_room_bed']355 assert results[0] is self.app['hostels']['hall-x']['hall-x_block_room_bed'] 313 356 314 357 class HostelsUITests(HostelsFullSetup): … … 622 665 result, 623 666 'bed_id,bed_number,bed_type,owner,hall,block,room,bed,' 624 'special_handling,sex,bt\r\nhall _block_room_bed,1,regular_male_fr,,'625 'hall ,block,room,bed,regular,male,fr\r\n'667 'special_handling,sex,bt\r\nhall-x_block_room_bed,1,regular_male_fr,,' 668 'hall-x,block,room,bed,regular,male,fr\r\n' 626 669 ) 627 670 return
Note: See TracChangeset for help on using the changeset viewer.