#-*- mode: python; mode: fold -*- from Globals import InitializeClass from AccessControl import ClassSecurityInfo from Products.CMFCore.utils import UniqueObject, getToolByName from Products.CMFCore.permissions import View from Products.CMFCore.permissions import ModifyPortalContent from Products.CPSCore.CPSBase import CPSBase_adder, CPSBaseFolder #from Products.CPSCore.CPSBase import CPSBaseDocument as BaseDocument from Products.CPSDocument.CPSDocument import CPSDocument from Products.CPSCore.CPSBase import CPSBaseBTreeFolder as BaseBTreeFolder from Products.WAeUP_SRP.WAeUPTables import AccommodationTable class AccoFolder(CPSDocument): ###( """ WAeUP AccoFolder containing Accommodation halls """ meta_type = 'AccoFolder' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(ModifyPortalContent,"generateFreeBedsList") ###( def generateFreeBedsList(self): """ generate the free Bedslist. """ freelist = AccommodationTable() l = self.portal_catalog({'meta_type': "Accommodation"}) halls = [] for h in l: halls.append(h.getObject()) for hall in halls: h = hall.getContent() for block in range(1,int(h.nr_of_blocks)): for floor in range(1,int(h.nr_of_floors)): for room in range(1,int(h.rooms_per_floor)): for bed in 'ABCDEFGH'[:int(h.beds_per_room)]: room_nr = floor*100 + room freelist.addRecord(bed = '%s_%d_%s' % (h.getId(),room_nr,bed), bed_type = "test") ###) InitializeClass(AccoFolder) def addAccoFolder(container, id, REQUEST=None, **kw): """Add a AccoFolder.""" ob = AccoFolder(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###) class Accommodation(CPSDocument): ###( """ WAeUP Accommodation containing Departments """ meta_type = 'Accommodation' portal_type = meta_type security = ClassSecurityInfo() security.declareProtected(View,"Title") ###( def Title(self): """compose title""" content = self.getContent() heading = getattr(content,'heading',None) if heading is None: return self.title return heading ###) InitializeClass(Accommodation) def addAccommodation(container, id, REQUEST=None, **kw): """Add a Accommodation.""" ob = Accommodation(id, **kw) return CPSBase_adder(container, ob, REQUEST=REQUEST) ###)