Changeset 13316 for main/waeup.kofa/trunk/src/waeup/kofa/hostels
- Timestamp:
- 14 Oct 2015, 09:34:30 (9 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/catalog.py
r7811 r13316 30 30 grok.context(IBed) 31 31 32 #bed_id = index.Field(attribute='bed_id')33 #bed_number = index.Field(attribute='bed_number')34 32 bed_type = index.Field(attribute='bed_type') 35 33 owner = index.Field(attribute='owner') -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/container.py
r13166 r13316 22 22 import pytz 23 23 from datetime import datetime 24 from zope.catalog.interfaces import ICatalog 25 from zope.component import queryUtility 24 26 from waeup.kofa.hostels.interfaces import IHostelsContainer, IHostel 25 27 from waeup.kofa.utils.logger import Logger … … 52 54 return 53 55 56 def releaseExpiredAllocations(self, n=7): 57 """Release bed if bed allocation has expired. Allocation expires 58 after `n` days if maintenance fee has not been paid. 59 """ 60 cat = queryUtility(ICatalog, name='beds_catalog') 61 results = cat.searchResults(owner=(None, None)) 62 counter = 0 63 for bed in results: 64 success = bed.releaseBedIfMaintenanceNotPaid(n=n) 65 if success: 66 counter += 1 67 return counter 68 54 69 @property 55 70 def expired(self): -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py
r13170 r13316 253 253 if self.owner == NOT_OCCUPIED: 254 254 return 255 else: 256 old_owner = self.owner 255 old_owner = self.owner 256 self.owner = NOT_OCCUPIED 257 notify(grok.ObjectModifiedEvent(self)) 258 accommodation_session = grok.getSite()[ 259 'hostels'].accommodation_session 260 try: 261 bedticket = grok.getSite()['students'][old_owner][ 262 'accommodation'][str(accommodation_session)] 263 except KeyError: 264 return '%s without bed ticket' % old_owner 265 bedticket.bed = None 266 tz = getUtility(IKofaUtils).tzinfo 267 timestamp = now(tz).strftime("%Y-%m-%d %H:%M:%S %Z") 268 bedticket.bed_coordinates = u'-- booking cancelled on %s --' % ( 269 timestamp,) 270 return old_owner 271 272 def releaseBedIfMaintenanceNotPaid(self, n=7): 273 if self.owner == NOT_OCCUPIED: 274 return 275 accommodation_session = grok.getSite()[ 276 'hostels'].accommodation_session 277 try: 278 bedticket = grok.getSite()['students'][self.owner][ 279 'accommodation'][str(accommodation_session)] 280 except KeyError: 281 return 282 if bedticket.maint_payment_made: 283 return 284 jetzt = datetime.utcnow() 285 days_ago = getattr(jetzt - bedticket.booking_date, 'days') 286 if days_ago > n: 257 287 self.owner = NOT_OCCUPIED 258 288 notify(grok.ObjectModifiedEvent(self)) 259 accommodation_session = grok.getSite()[260 'hostels'].accommodation_session261 try:262 bedticket = grok.getSite()['students'][old_owner][263 'accommodation'][str(accommodation_session)]264 except KeyError:265 return '%s without bed ticket' % old_owner266 289 bedticket.bed = None 267 290 tz = getUtility(IKofaUtils).tzinfo 268 291 timestamp = now(tz).strftime("%Y-%m-%d %H:%M:%S %Z") 269 bedticket.bed_coordinates = u'-- booking cancelled on %s--' % (292 bedticket.bed_coordinates = u'-- booking expired (%s) --' % ( 270 293 timestamp,) 271 return old_owner 294 return True 295 return 272 296 273 297 def writeLogMessage(self, view, message): -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/interfaces.py
r13280 r13316 71 71 """ 72 72 73 def releaseExpiredAllocations(n): 74 """Release bed if bed allocation has expired. Allocation expires 75 after `n` days if maintenance fee has not been paid. 76 """ 77 73 78 def writeLogMessage(view, message): 74 79 """Add an INFO message to hostels.log. … … 230 235 def switchReservation(): 231 236 """Reserves bed or relases reserved bed respectively. 237 """ 238 239 def releaseBedIfMaintenanceNotPaid(): 240 """Release bed if maintenance fee has not been paid on time. 232 241 """ 233 242 -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py
r13315 r13316 35 35 from waeup.kofa.hostels.interfaces import ( 36 36 IHostelsContainer, IHostel, IBed) 37 from waeup.kofa.hostels.vocabularies import NOT_OCCUPIED 37 38 from waeup.kofa.hostels.container import HostelsContainer 38 39 from waeup.kofa.hostels.hostel import Hostel, Bed … … 173 174 clearSite() 174 175 shutil.rmtree(self.dc_root) 176 177 class HostelsContainerTests(HostelsFullSetup): 178 179 layer = FunctionalLayer 180 181 def test_release_expired_allocations(self): 182 cat = queryUtility(ICatalog, name='beds_catalog') 183 bedticket = BedTicket() 184 bedticket.booking_session = 2004 185 bedticket.bed_coordinates = u'anything' 186 self.student['accommodation'].addBedTicket(bedticket) 187 self.app[ 188 'hostels']['hall-x']['hall_block_room_bed'].owner = self.student_id 189 notify(grok.ObjectModifiedEvent( 190 self.app['hostels']['hall-x']['hall_block_room_bed'])) 191 results = cat.searchResults(owner=(self.student_id, self.student_id)) 192 self.assertEqual(len(results), 1) 193 released = self.app['hostels'].releaseExpiredAllocations(7) 194 self.assertEqual(released, 0) 195 delta = timedelta(days=10) 196 bedticket.booking_date = datetime.utcnow() - delta 197 released = self.app['hostels'].releaseExpiredAllocations(7) 198 self.assertEqual(released, 1) 199 results = cat.searchResults(owner=(self.student_id, self.student_id)) 200 self.assertEqual(len(results), 0) 201 self.assertMatches(bedticket.display_coordinates, 202 '-- booking expired (2015-10-14 08:35:38 UTC) --') 203 self.assertEqual( 204 self.app['hostels']['hall-x']['hall_block_room_bed'].owner, 205 NOT_OCCUPIED) 206 return 175 207 176 208 class BedCatalogTests(HostelsFullSetup): … … 330 362 self.assertMatches(bedticket.bed_coordinates, 331 363 u' -- booking cancelled on <YYYY-MM-DD hh:mm:ss> UTC --') 332 # The catalog wasupdated.364 # The catalog has been updated. 333 365 results = cat.searchResults(owner=(self.student_id, self.student_id)) 334 366 assert len(results) == 0
Note: See TracChangeset for help on using the changeset viewer.