import grok from zope.component.interfaces import IFactory from zope.interface import implementedBy from waeup.sirp.interfaces import IWAeUPSIRPPluggable from waeup.sirp.university.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, *args, **kw): return FacultyContainer(*args, **kw) def getInterfaces(self): return implementedBy(FacultyContainer) class AcademicsPlugin(grok.GlobalUtility): """A plugin that tells universities how to create a faculty container. """ grok.implements(IWAeUPSIRPPluggable) factory_name = u'waeup.FacultyContainer' name = 'faculties'