- Timestamp:
- 25 Oct 2012, 09:44:02 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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}))
Note: See TracChangeset for help on using the changeset viewer.