## ## interfaces.py from zope.interface import Attribute, invariant, Invalid from zope import schema from waeup.sirp.interfaces import IWAeUPObject from waeup.sirp.hostels.vocabularies import ( bed_letters, blocks, special_handling) class IHostelsContainer(IWAeUPObject): """A container for all kind of hostel objects. """ class IHostel(IWAeUPObject): """A base representation of hostels. """ def loggerInfo(ob_class, comment): """Adds an INFO message to the log file """ def updateBeds(): """Fill hostel with beds or update beds. """ hostel_id = schema.TextLine( title = u'Hostel Id', readonly = True, ) sort_id = schema.Int( title = u'Sort Id', required = True, default = 10, ) hostel_name = schema.TextLine( title = u'Hall Name', required = True, default = u'Hall 1', ) floors_per_block = schema.Int( title = u'Floors per Block', required = True, default = 3, ) rooms_per_floor = schema.Int( title = u'Rooms per Floor', required = True, default = 20, ) #beds_per_room = schema.Int( # title = u'Beds per Room', # required = True, # default = 6, # ) blocks_for_female = schema.List( title = u'Blocks for Female Students', value_type = schema.Choice( vocabulary = blocks ), ) blocks_for_male = schema.List( title = u'Blocks for Male Students', value_type = schema.Choice( vocabulary = blocks ), ) beds_for_fresh = schema.List( title = u'Beds for Fresh Students', value_type = schema.Choice( vocabulary = bed_letters ), ) beds_for_returning = schema.List( title = u'Beds for Returning Students', value_type = schema.Choice( vocabulary = bed_letters ), ) beds_for_final = schema.List( title = u'Beds for Final Year Students', value_type = schema.Choice( vocabulary = bed_letters ), ) special_handling = schema.Choice( title = u'Special Handling', vocabulary = special_handling, required = True, default = u'none', ) reserved = schema.TextLine( title = u'Reserved Rooms', required = False, default = u'', ) @invariant def blocksOverlap(hostel): bfe = hostel.blocks_for_female bma = hostel.blocks_for_male if set(bfe).intersection(set(bma)): raise Invalid('Female and male blocks overlap.') @invariant def bedsOverlap(hostel): bfr = hostel.beds_for_fresh bre = hostel.beds_for_returning bfi = hostel.beds_for_final if (set(bfr).intersection(set(bre)) or set(bfr).intersection(set(bfi)) or set(bre).intersection(set(bfi))): raise Invalid('Bed categories overlap.') #@invariant #def numberOfBeds(hostel): # bfr = hostel.beds_for_fresh # bre = hostel.beds_for_returning # bfi = hostel.beds_for_final # if len(bfr + bre + bfi) != hostel.beds_per_room: # raise Invalid( # 'Bed categories and number of beds per room do not match.') class IBed(IWAeUPObject): """A base representation of beds. """ def loggerInfo(ob_class, comment): """Adds an INFO message to the log file """ def getBedCoordinates(): """Determine the coordinates from bed_id. """ bed_id = schema.TextLine( title = u'Bed Id', required = True, default = u'', ) bed_type = schema.TextLine( title = u'Bed Type', required = True, default = u'', ) sort_id = schema.Int( title = u'Sort Id', required = True, default = 100, ) owner = schema.TextLine( title = u'Owner (Student)', required = True, default = u'', )