Changeset 9414 for main/waeup.kofa/trunk/src/waeup/kofa/hostels
- Timestamp:
- 25 Oct 2012, 09:44:02 (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
r9217 r9414 37 37 from waeup.kofa.hostels.hostel import Hostel 38 38 from waeup.kofa.hostels.interfaces import ( 39 IHostelsContainer, IHostel, IBed , IBedAllocateStudent)39 IHostelsContainer, IHostel, IBed) 40 40 from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget 41 41 … … 350 350 """ View to edit bed data 351 351 """ 352 grok.context(IBed AllocateStudent)352 grok.context(IBed) 353 353 grok.name('index') 354 354 grok.require('waeup.manageHostels') 355 form_fields = grok.AutoFields(IBed AllocateStudent).omit(355 form_fields = grok.AutoFields(IBed).omit( 356 356 'bed_id', 'bed_number', 'bed_type') 357 357 label = _('Allocate student') -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/hostel.py
r9202 r9414 26 26 from waeup.kofa.utils.helpers import attrs_to_fields 27 27 from waeup.kofa.hostels.vocabularies import NOT_OCCUPIED 28 from waeup.kofa.hostels.interfaces import IHostel, IBed , IBedAllocateStudent28 from waeup.kofa.hostels.interfaces import IHostel, IBed 29 29 from waeup.kofa.students.interfaces import IBedTicket 30 30 from waeup.kofa.interfaces import IKofaUtils … … 143 143 """This is a bed. 144 144 """ 145 grok.implements(IBed , IBedAllocateStudent)145 grok.implements(IBed) 146 146 grok.provides(IBed) 147 147 -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/interfaces.py
r9400 r9414 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 from grok import getSite 18 19 from datetime import datetime 20 from zope.component import getUtility 21 from zope.catalog.interfaces import ICatalog 19 22 from zope.interface import invariant, Invalid, Attribute 20 23 from zope import schema … … 23 26 from waeup.kofa.interfaces import MessageFactory as _ 24 27 from waeup.kofa.hostels.vocabularies import ( 25 bed_letters, blocks, SpecialHandlingSource, StudentSource) 28 bed_letters, blocks, SpecialHandlingSource, 29 NOT_OCCUPIED) 26 30 27 31 class IHostelsContainer(IKofaObject): … … 236 240 ) 237 241 238 239 240 class IBedAllocateStudent(IBed): 241 """A representation of beds for allocation form only. 242 243 """ 244 245 owner = schema.Choice( 246 title = _(u'Owner (Student)'), 247 source = StudentSource(), 248 default = None, 249 required = True, 250 ) 242 @invariant 243 def allowed_owners(bed): 244 if bed.owner == NOT_OCCUPIED: 245 return 246 catalog = getUtility(ICatalog, name='students_catalog') 247 accommodation_session = getSite()['hostels'].accommodation_session 248 students = catalog.searchResults(current_session=( 249 accommodation_session,accommodation_session)) 250 student_ids = [student.student_id for student in students] 251 if not bed.owner in student_ids: 252 raise Invalid(_( 253 "Either student does not exist or is not in accommodation session.")) 254 catalog = getUtility(ICatalog, name='beds_catalog') 255 beds = catalog.searchResults(owner=(bed.owner,bed.owner)) 256 if len(beds): 257 allocated_bed = [bed.bed_id for bed in beds][0] 258 raise Invalid(_( 259 "This student resides in bed ${a}.", mapping = {'a':allocated_bed})) -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/tests.py
r9283 r9414 313 313 self.assertMatches( 314 314 '...No allocated bed selected...', self.browser.contents) 315 # Managers can manually allocate students after cancellation315 # Managers can manually allocate eligible students after cancellation 316 316 self.browser.open(self.container_path + '/hall-1/hall-1_A_101_A') 317 self.browser.getControl(name="form.owner").value = [self.student_id] 317 self.browser.getControl(name="form.owner").value = 'nonsense' 318 self.browser.getControl("Save").click() 319 self.assertMatches( 320 "...Either student does not exist or is not in accommodation session...", 321 self.browser.contents) 322 self.browser.getControl(name="form.owner").value = self.student_id 318 323 self.browser.getControl("Save").click() 319 324 self.assertMatches("...Form has been saved...", self.browser.contents) 325 # Students can only be allocated once 326 self.browser.open(self.container_path + '/hall-1/hall-1_A_101_B') 327 self.browser.getControl(name="form.owner").value = self.student_id 328 self.browser.getControl("Save").click() 329 self.assertMatches( 330 "...This student resides in bed hall-1_A_101_A...", 331 self.browser.contents) 320 332 # If we open the same form again, we will be redirected to hostel 321 333 # manage page. Beds must be released first before they can be … … 347 359 # Also the number of the bed has changed. 348 360 self.assertFalse(new_number == old_number) 349 # The number of occupied bed are displayed on container page.361 # The number of occupied beds are displayed on container page. 350 362 self.browser.open(self.container_path) 351 363 self.assertTrue('1 of 8' in self.browser.contents) -
main/waeup.kofa/trunk/src/waeup/kofa/hostels/vocabularies.py
r9400 r9414 27 27 28 28 NOT_OCCUPIED = u'not occupied' 29 30 class StudentSource(BasicContextualSourceFactory):31 """A students source delivers all students in accommodation session.32 """33 34 def acco_students(self, context):35 catalog = getUtility(ICatalog, name='students_catalog')36 accommodation_session = getSite()['hostels'].accommodation_session37 students = catalog.searchResults(current_session=(38 accommodation_session,accommodation_session))39 existing_students = [40 context.__parent__[key].owner41 for key in context.__parent__.keys()]42 students = [student for student in students43 if not student.student_id in existing_students]44 students = sorted(list(students),45 key=lambda value: value.student_id)46 return dict([(student.student_id,student.fullname) for student in students])47 48 def getValues(self, context):49 return self.acco_students(context).keys()50 51 def getToken(self, context, value):52 return value53 54 def getTitle(self, context, value):55 return "%s - %s" % (value, self.acco_students(context)[value])56 29 57 30 class SpecialHandlingSource(ContextualDictSourceFactoryBase):
Note: See TracChangeset for help on using the changeset viewer.