import grok from zope.component.interfaces import IFactory from zope.interface import implementedBy from waeup.sirp.interfaces import IFacultyContainer, IFaculty class FacultyContainer(grok.Container): """See interfaces for description. """ grok.implements(IFacultyContainer) grok.require('waeup.manageUniversity') def addFaculty(self, faculty): if not IFaculty.providedBy(faculty): raise TypeError('FacultyContainers contain only IFaculty instances') self[faculty.code] = faculty return def clear(self): keys = self.keys() for key in keys: del self[key] def getName(self, key): if key in self.keys(): fac = self[key] prefix = fac.title_prefix prefix = prefix[0].upper() + prefix[1:] return '%s of %s' % (prefix, fac.title) class FacultyContainerFactory(grok.GlobalUtility): """A factory for faculty containers. """ grok.implements(IFactory) grok.name(u'waeup.FacultyContainer') title = u"Create a new faculty container.", description = u"This factory instantiates new faculty containers." def __call__(self): return FacultyContainer() def getInterfaces(self): return implementedBy(FacultyContainer)