Changeset 17313 for main/waeup.kofa/trunk/src/waeup/kofa/hostels
- Timestamp:
- 25 Jan 2023, 08:52:51 (2 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/hostels
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/hostels/__init__.py
r7811 r17313 1 """This package contains everything regarding hostels.2 """3 1 # Make this a package. 4 from waeup.kofa.hostels.container import HostelsContainer5 from waeup.kofa.hostels.hostel import Hostel, Bed6 7 __all__ = [8 'HostelsContainer',9 'Hostel',10 'Bed',11 ] -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/batching.py
r13434 r17313 83 83 class BedProcessor(BatchProcessor): 84 84 """The Bed Procesor update beds. It allocates students 85 to empty beds and switches the reservation status of beds. ``1``86 means reserved and ``0`` unreserved. Beds cannot be released87 by import.85 to empty beds and switches the reservation or blockade status of beds. ``1`` 86 means reserved (or blocked) and ``0`` unreserved (or unblocked). 87 Beds cannot be released by import. 88 88 """ 89 89 grok.implements(IBatchProcessor) … … 103 103 @property 104 104 def available_fields(self): 105 return self.location_fields + ['reserved', ' owner']105 return self.location_fields + ['reserved', 'blocked', 'owner'] 106 106 107 107 def parentsExist(self, row, site): … … 132 132 if row.get('owner') and obj.owner != NOT_OCCUPIED: 133 133 return 'Bed is occupied.' 134 # Check if bed is blocked and not unblocked by the importer 135 if obj.bed_type.endswith('blocked') and \ 136 row.get('owner') not in (None, '', IGNORE_MARKER) and \ 137 row.get('blocked') != '0': 138 return 'Bed is blocked.' 134 139 135 140 def checkConversion(self, row, mode='ignore'): … … 142 147 if reserved not in (None, IGNORE_MARKER, '', '0', '1'): 143 148 errs.append(('reserved','invalid value')) 149 blocked = row.get('blocked') 150 if blocked not in (None, IGNORE_MARKER, '', '0', '1'): 151 errs.append(('blocked','invalid value')) 144 152 owner = row.get('owner') 145 153 if owner not in (None, '', IGNORE_MARKER): … … 168 176 obj.bookBed(owner) 169 177 changed.append('owner=%s' % owner) 178 sh, sex, bt = obj.bed_type.split('_') 170 179 reserved = row.get('reserved') 171 sh, sex, bt = obj.bed_type.split('_')172 180 if (reserved == '1' and bt != 'reserved') or \ 173 181 (reserved == '0'and bt == 'reserved'): 174 message = obj.switchReservation() 182 message = obj.switchBed('reserved') 183 changed.append(message) 184 blocked = row.get('blocked') 185 if (blocked == '1' and bt != 'blocked') or \ 186 (blocked == '0'and bt == 'blocked'): 187 message = obj.switchBed('blocked') 175 188 changed.append(message) 176 189 # Log actions... -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/browser.py
r15633 r17313 266 266 grok.name('addhostel') 267 267 #grok.template('hosteladdpage') 268 form_fields = grok.AutoFields(IHostel).omit(' beds_reserved', 'hostel_id')268 form_fields = grok.AutoFields(IHostel).omit('hostel_id') 269 269 label = _('Add hostel') 270 270 pnav = 5 … … 294 294 grok.require('waeup.viewHostels') 295 295 grok.template('hostelpage') 296 form_fields = grok.AutoFields(IHostel) .omit('beds_reserved')296 form_fields = grok.AutoFields(IHostel) 297 297 pnav = 5 298 298 … … 315 315 grok.name('manage') 316 316 grok.require('waeup.manageHostels') 317 form_fields = grok.AutoFields(IHostel).omit('hostel_id' , 'beds_reserved')317 form_fields = grok.AutoFields(IHostel).omit('hostel_id') 318 318 grok.template('hostelmanagepage') 319 319 label = _('Manage hostel') … … 322 322 tabtwoactions = [_('Update all beds'), 323 323 _('Switch reservation of selected beds'), 324 _('Switch blockade of selected beds'), 324 325 _('Release selected beds'), 325 326 _('Clear hostel')] … … 337 338 338 339 @action(_('Update all beds'), style='primary', 339 warning=_('Attention: The updater removes all reservation flags of existing beds.' 340 ' You really want to update?')) 340 warning=_('Attention: The updater removes all reservation and ' 341 'blockade flags of existing beds. ' 342 'You really want to update?')) 341 343 def updateBeds(self, **data): 342 344 if not grok.getSite()['configuration'].maintmode_enabled_by: … … 364 366 return 365 367 366 @action(_('Switch reservation of selected beds')) 367 def switchReservations(self, **data): 368 def _switchBeds(self, switch_type): 368 369 form = self.request.form 369 370 if 'val_id' in form: … … 380 381 preferred_language = self.request.cookies.get('kofa.language') 381 382 for bed_id in child_id: 382 message = self.context[bed_id].switch Reservation()383 message = self.context[bed_id].switchBed(switch_type) 383 384 switched.append('%s (%s)' % (bed_id,message)) 384 385 m_translated = translate(message, 'waeup.kofa', … … 396 397 self.context.writeLogMessage(self, 'switched: %s' % message) 397 398 self.redirect(self.url(self.context, '@@manage')+'#tab2') 399 return 400 401 402 @action(_('Switch reservation of selected beds')) 403 def switchReservations(self, **data): 404 self._switchBeds('reserved') 405 return 406 407 @action(_('Switch blockade of selected beds')) 408 def switchBockade(self, **data): 409 self._switchBeds('blocked') 398 410 return 399 411 … … 456 468 457 469 def update(self): 470 if self.context.bed_type.endswith('blocked'): 471 # No student can reside in a blocked bed. 472 self.redirect(self.url(self.context.__parent__, '@@manage')+'#tab2') 458 473 if self.context.owner != NOT_OCCUPIED: 459 474 # Don't use this form for exchanging students. -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/browser_templates/hostelmanagepage.pt
r13346 r17313 59 59 <span tal:content="value/owner">OWNER</span> 60 60 </a> 61 <a tal:condition="python: value.owner == view.not_occupied "61 <a tal:condition="python: value.owner == view.not_occupied and not value.bed_type.endswith('blocked')" 62 62 tal:attributes="href python: view.url(value)" 63 63 i18n:translate=""> -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py
r15944 r17313 198 198 return self.owner 199 199 200 def switch Reservation(self):201 """ Reserves or unreserve bed respectively.200 def switchBed(self, switch_type): 201 """Switches bed. `switch_type` is either `reserved` or `blocked`. 202 202 """ 203 203 sh, sex, bt = self.bed_type.split('_') … … 209 209 beds_for_final = getattr(hostel,'beds_for_final',[]) 210 210 bed_string = u'%s_%s_%s' % (block, room_nr, bed) 211 if bt == 'reserved':211 if bt == switch_type: 212 212 bt = 'all' 213 213 if bed in beds_for_fresh: … … 220 220 bt = 're' 221 221 bt = u'%s_%s_%s' % (sh, sex, bt) 222 message = _(u'un reserved')222 message = _(u'un' + switch_type) 223 223 else: 224 bt = u'%s_%s_ reserved' % (sh, sex)225 message = _(u'reserved')224 bt = u'%s_%s_%s' % (sh, sex, switch_type) 225 message = switch_type 226 226 self.bed_type = bt 227 227 notify(grok.ObjectModifiedEvent(self)) -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/interfaces.py
r17176 r17313 28 28 bed_letters, blocks, SpecialHandlingSource, 29 29 NOT_OCCUPIED) 30 from waeup.kofa.students.interfaces import (IStudentsUtils)30 from waeup.kofa.students.interfaces import IStudentsUtils 31 31 32 32 # Define a validation method for sort ids … … 248 248 """ 249 249 250 def switch Reservation():251 """ Reserves bed or relases reserved bed respectively.250 def switchBed(switch_type): 251 """Switches reservation or blockade. 252 252 """ 253 253 -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/sample_bed_data.csv
r13432 r17313 1 hostel_id,bed_id,owner,reserved 2 block-a-upper-hostel,block-a-upper-hostel_A_101_A,,0 3 block-a-upper-hostel,block-a-upper-hostel_A_101_B,,1 4 block-a-upper-hostel,block-a-upper-hostel_A_101_C,,2 5 block-a-upper-hostel,block-a-upper-hostel_A_101_D,K1000000,0 6 block-a-upper-hostel,block-a-upper-hostel_A_101_E,K999,0 1 hostel_id,bed_id,owner,reserved,blocked 2 block-a-upper-hostel,block-a-upper-hostel_A_101_A,,0,1 3 block-a-upper-hostel,block-a-upper-hostel_A_101_B,,1,0 4 block-a-upper-hostel,block-a-upper-hostel_A_101_C,,2,0 5 block-a-upper-hostel,block-a-upper-hostel_A_101_D,K1000000,0,0 6 block-a-upper-hostel,block-a-upper-hostel_A_101_E,K999,0,0 -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py
r17176 r17313 31 31 from zope.security.interfaces import Unauthorized 32 32 from zope.catalog.interfaces import ICatalog 33 from zope.component import queryUtility, getUtility 33 from zope.component import queryUtility, getUtility, createObject 34 34 from waeup.kofa.app import University 35 35 from waeup.kofa.hostels.interfaces import ( … … 54 54 BED_SAMPLE_DATA = open( 55 55 os.path.join(os.path.dirname(__file__), 'sample_bed_data.csv'), 56 'rb').read() 57 58 BED_SAMPLE_DATA_2 = open( 59 os.path.join(os.path.dirname(__file__), 'sample_bed_data_2.csv'), 56 60 'rb').read() 57 61 … … 396 400 (u'hall-1_A_101_C', u'regular_female_reserved'), 397 401 (u'hall-1_A_101_D', u'regular_female_reserved')]) 402 # Block beds. 403 self.browser.getControl("Switch blockade", index=0).click() 404 self.assertTrue('No item selected' in self.browser.contents) 405 ctrl = self.browser.getControl(name='val_id') 406 ctrl.getControl(value='hall-1_A_101_A').selected = True 407 ctrl.getControl(value='hall-1_A_101_B').selected = True 408 ctrl.getControl(value='hall-1_A_101_C').selected = True 409 ctrl.getControl(value='hall-1_A_101_D').selected = True 410 self.browser.getControl("Switch blockade", index=0).click() 411 self.assertTrue('Successfully switched beds: hall-1_A_101_A (blocked)' 412 in self.browser.contents) 413 self.assertEqual(self.app['hostels']['hall-1'][ 414 'hall-1_A_101_D'].bed_type, 'regular_female_blocked') 415 # The catalog has been updated. 416 results = cat.searchResults( 417 bed_type=('regular_female_all', 'regular_female_all')) 418 results = [(x.bed_id, x.bed_type) for x in results] 419 self.assertEqual(results, 420 [(u'hall-1_A_101_E', u'regular_female_all'), 421 (u'hall-1_B_101_D', u'regular_female_all'), 422 (u'hall-1_B_101_E', u'regular_female_all')]) 423 results = cat.searchResults( 424 bed_type=('regular_female_blocked', 'regular_female_blocked')) 425 results = [(x.bed_id, x.bed_type) for x in results] 426 self.assertEqual(results, 427 [(u'hall-1_A_101_A', u'regular_female_blocked'), 428 (u'hall-1_A_101_B', u'regular_female_blocked'), 429 (u'hall-1_A_101_C', u'regular_female_blocked'), 430 (u'hall-1_A_101_D', u'regular_female_blocked')]) 398 431 # Change hostel configuration with one bed booked. 399 432 hall['hall-1_A_101_E'].owner = u'anyid' … … 672 705 logcontent = open(self.logfile).read() 673 706 self.assertEqual( 674 'owner,bed_id,hostel_id,reserved, --ERRORS--\r\n'675 '<IGNORE>,block-a-upper-hostel_A_101_C,block-a-upper-hostel,2, '707 'owner,bed_id,hostel_id,reserved,blocked,--ERRORS--\r\n' 708 '<IGNORE>,block-a-upper-hostel_A_101_C,block-a-upper-hostel,2,0,' 676 709 'reserved: invalid value\r\n' 677 'K999,block-a-upper-hostel_A_101_E,block-a-upper-hostel,0, '710 'K999,block-a-upper-hostel_A_101_E,block-a-upper-hostel,0,0,' 678 711 'owner: student does not exist\r\n', 679 712 fail_file_content) 680 713 self.assertTrue( 681 714 'system - Bed Processor (update only) - sample_bed_data - ' 682 'block-a-upper-hostel_A_101_A - updated: nothing'715 'block-a-upper-hostel_A_101_A - updated: blocked' 683 716 in logcontent) 684 717 self.assertTrue( … … 697 730 ['block-a-upper-hostel_A_101_B'].bed_type, 698 731 'regular_female_reserved') 732 # Add another student K1000001 733 student = createObject('waeup.Student') 734 student.firstname = u'Claus' 735 student.lastname = u'Tester' 736 self.app['students'].addStudent(student) 737 # Try to allocate this student to a blocked bed 738 739 open(self.csv_file, 'wb').write(BED_SAMPLE_DATA_2) 740 num, num_warns, fin_file, fail_file = self.processor.doImport( 741 self.csv_file, BED_HEADER_FIELDS, 'update') 742 fail_file_content = open(fail_file).read() 743 self.assertEqual( 744 'owner,bed_id,hostel_id,reserved,blocked,--ERRORS--\r\n' 745 'K1000001,block-a-upper-hostel_A_101_A,block-a-upper-hostel,' 746 '<IGNORE>,<IGNORE>,Bed is blocked.\r\n', 747 fail_file_content) 699 748 shutil.rmtree(os.path.dirname(fin_file)) 700 749 shutil.rmtree(self.workdir)
Note: See TracChangeset for help on using the changeset viewer.