import grok from zope.component.interfaces import IFactory from zope.interface import implementedBy from waeup.sirp.interfaces import IHostelContainer, IHostel class HostelContainer(grok.Container): grok.implements(IHostelContainer) grok.require('waeup.manageUniversity') # A simple counter for ids. next_id = 0L def addHostel(self, hostel): if not IHostel.providedBy(hostel): raise TypeError('HostelContainers contain only IHostel instances') id = str(self.next_id) self[id] = hostel while self.next_id in self.keys(): # Look for next unused int... self.next_id += 1 return id class HostelContainerFactory(grok.GlobalUtility): """A factory for faculty containers. """ grok.implements(IFactory) grok.name(u'waeup.HostelContainer') title = u"Create a new hostel container.", description = u"This factory instantiates new hostel containers." def __call__(self): return HostelContainer() def getInterfaces(self): return implementedBy(HostelContainer)