Changeset 7068 for main/waeup.sirp/trunk/src/waeup/sirp/hostels
- Timestamp:
- 10 Nov 2011, 18:56:18 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/hostels
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py
r7042 r7068 35 35 from waeup.sirp.authentication import get_principal_role_manager 36 36 from waeup.sirp.hostels.container import HostelsContainer 37 from waeup.sirp.hostels.hostel import Hostel, NOT_OCCUPIED 38 from waeup.sirp.hostels.interfaces import IHostelsContainer, IHostel 37 from waeup.sirp.hostels.vocabularies import NOT_OCCUPIED 38 from waeup.sirp.hostels.hostel import Hostel 39 from waeup.sirp.hostels.interfaces import ( 40 IHostelsContainer, IHostel, IBed, IBedAllocateStudent) 39 41 40 42 def write_log_message(view, message): … … 86 88 def title(self): 87 89 return self.context.hostel_name 90 91 class BedBreadcrumb(Breadcrumb): 92 """A breadcrumb for the hostel container. 93 """ 94 grok.context(IBed) 95 96 def title(self): 97 co = self.context.getBedCoordinates() 98 return 'Block %s, Room %s, Bed %s' % (co[1], co[2], co[3]) 88 99 89 100 class HostelsContainerPage(WAeUPDisplayFormPage): … … 277 288 released = [] 278 289 for bed_id in child_id: 279 try: 280 message = self.context[bed_id].releaseBed() 281 released.append('%s (%s)' % (bed_id,message)) 282 except: 283 self.flash('Could not release %s: %s: %s' % ( 284 id, sys.exc_info()[0], sys.exc_info()[1])) 285 self.redirect(self.url(self.context, '@@manage')+'#tab-2') 286 return 290 message = self.context[bed_id].releaseBed() 291 released.append('%s (%s)' % (bed_id,message)) 287 292 if len(released): 288 293 message = ', '.join(released) … … 291 296 self.redirect(self.url(self.context, '@@manage')+'#tab-2') 292 297 return 298 299 class BedManageFormPage(WAeUPEditFormPage): 300 """ View to edit bed data 301 """ 302 grok.context(IBedAllocateStudent) 303 grok.name('index') 304 grok.require('waeup.manageHostels') 305 form_fields = grok.AutoFields(IBedAllocateStudent).omit( 306 'bed_id').omit('bed_number').omit('bed_type') 307 label = 'Allocate student' 308 pnav = 5 309 310 @property 311 def title(self): 312 co = self.context.getBedCoordinates() 313 return '%s, Block %s, Room %s, Bed %s' % ( 314 self.context.__parent__.hostel_name, co[1], co[2], co[3]) 315 316 @grok.action('Save') 317 def save(self, **data): 318 msave(self, **data) 319 self.redirect(self.url(self.context.__parent__, '@@manage')+'#tab-2') 320 return 321 322 def update(self): 323 if self.context.owner != NOT_OCCUPIED: 324 # Don't use this form for exchanging students. 325 # Beds must be released first before they can be allocated to 326 # other students. 327 self.redirect(self.url(self.context.__parent__, '@@manage')+'#tab-2') 328 return -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser_templates/hostelmanagepage.pt
r7012 r7068 88 88 <span tal:content="value/owner">Owner</span> 89 89 </a> 90 <a tal:condition="python: value.owner == view.not_occupied" 91 tal:attributes="href python: view.url(value)"> 92 [allocate student] 93 </a> 90 94 </td> 91 95 </tr> -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/catalog.py
r7006 r7068 21 21 bed_type = index.Field(attribute='bed_type') 22 22 owner = index.Field(attribute='owner') 23 24 class BedQueryResultItem(object):25 grok.implements(IQueryResultItem)26 27 title = u'Bed Query Item'28 description = u'Some bed found in a search'29 30 def __init__(self, context, view):31 self.context = context32 self.url = view.url(context)33 self.bed_id = context.bed_id34 self.bed_type = context.bed_type35 self.bed_number = context.bed_number -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/hostel.py
r7058 r7068 22 22 from grok import index 23 23 from waeup.sirp.utils.helpers import attrs_to_fields 24 from waeup.sirp.hostels.interfaces import IHostel, IBed 24 from waeup.sirp.hostels.vocabularies import NOT_OCCUPIED 25 from waeup.sirp.hostels.interfaces import IHostel, IBed, IBedAllocateStudent 25 26 from waeup.sirp.students.interfaces import IBedTicket 26 27 NOT_OCCUPIED = u'not occupied'28 27 29 28 class Hostel(grok.Container): … … 121 120 """This is a bed. 122 121 """ 123 grok.implements(IBed )122 grok.implements(IBed, IBedAllocateStudent) 124 123 grok.provides(IBed) 125 124 … … 208 207 of the bed is cleared (set to NOT_OCCUPIED). 209 208 """ 210 allocated_bed = bedticket.bed211 allocated_bed.owner = NOT_OCCUPIED212 notify(grok.ObjectModifiedEvent(allocated_bed))209 if bedticket.bed != None: 210 bedticket.bed.owner = NOT_OCCUPIED 211 notify(grok.ObjectModifiedEvent(bedticket.bed)) -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/interfaces.py
r6996 r7068 5 5 from waeup.sirp.interfaces import IWAeUPObject 6 6 from waeup.sirp.hostels.vocabularies import ( 7 bed_letters, blocks, special_handling )7 bed_letters, blocks, special_handling, StudentSource) 8 8 9 9 class IHostelsContainer(IWAeUPObject): … … 172 172 default = u'', 173 173 ) 174 175 176 177 class IBedAllocateStudent(IBed): 178 """A representation of beds for allocation form only. 179 180 """ 181 182 owner = schema.Choice( 183 title = u'Owner (Student)', 184 source = StudentSource(), 185 default = None, 186 required = True, 187 ) -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/tests.py
r7045 r7068 108 108 self.student['studycourse'].current_session = 2004 109 109 self.student['studycourse'].entry_session = 2004 110 # The students_catalog must be informed that the 111 # session attribute has changed 112 notify(grok.ObjectModifiedEvent(self.student)) 110 113 111 114 # Set accommodation_session … … 125 128 126 129 self.container_path = 'http://localhost/app/hostels' 130 self.student_path = 'http://localhost/app/students/%s' % self.student_id 127 131 self.manage_container_path = self.container_path + '/@@manage' 128 132 self.add_hostel_path = self.container_path + '/addhostel' … … 269 273 self.browser.open(self.container_path + '/hall-1/manage') 270 274 ctrl = self.browser.getControl(name='val_id') 275 self.browser.getControl("Release selected beds", index=0).click() 276 self.assertMatches("...No item selected...", self.browser.contents) 277 ctrl = self.browser.getControl(name='val_id') 271 278 ctrl.getControl(value='hall-1_A_101_D').selected = True 272 279 self.browser.getControl("Release selected beds", index=0).click() … … 276 283 self.assertMatches(bedticket.bed_coordinates, 277 284 u' -- booking cancelled on <YYYY-MM-DD hh:mm:ss> --') 285 # Managers can manually allocate studenst after cancellation 286 self.browser.open(self.container_path + '/hall-1/hall-1_A_101_A') 287 self.browser.getControl(name="form.owner").value = [self.student_id] 288 self.browser.getControl("Save").click() 289 self.assertMatches("...Form has been saved...", self.browser.contents) 278 290 # Remove entire hostel 279 291 self.browser.open(self.manage_container_path) -
main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py
r6973 r7068 1 1 """Vocabularies and sources for the accommodation section. 2 2 """ 3 from grok import getSite 4 from zope.component import getUtility 5 from zope.catalog.interfaces import ICatalog 6 from zc.sourcefactory.contextual import BasicContextualSourceFactory 3 7 from zc.sourcefactory.basic import BasicSourceFactory 4 8 from waeup.sirp.interfaces import SimpleWAeUPVocabulary 5 9 10 NOT_OCCUPIED = u'not occupied' 11 12 class StudentSource(BasicContextualSourceFactory): 13 """A students source delivers all students in accommodation session. 14 """ 15 16 def acco_students(self, context): 17 catalog = getUtility(ICatalog, name='students_catalog') 18 accommodation_session = getSite()['configuration'].accommodation_session 19 students = catalog.searchResults(current_session=( 20 accommodation_session,accommodation_session)) 21 try: 22 existing_students = [ 23 context.__parent__[key].owner 24 for key in context.__parent__.keys()] 25 except AttributeError: 26 return {NOT_OCCUPIED:NOT_OCCUPIED} 27 students = [student for student in students 28 if not student.student_id in existing_students] 29 students = sorted(list(students), 30 key=lambda value: value.student_id) 31 return dict([(student.student_id,student.fullname) for student in students]) 32 33 def getValues(self, context): 34 return self.acco_students(context).keys() 35 36 def getToken(self, context, value): 37 return value 38 39 def getTitle(self, context, value): 40 return "%s - %s" % (value, self.acco_students(context)[value]) 6 41 7 42 bed_letters = SimpleWAeUPVocabulary(
Note: See TracChangeset for help on using the changeset viewer.