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 creates a faculty container inside a university. """ grok.implements(IWAeUPSIRPPluggable) grok.name('faculties') def setup(self, site, name, logger): if 'faculties' in site.keys(): logger.warn('Could not create faculty container in WAeUP SIRP.') return site['faculties'] = FacultyContainer() logger.info('Created faculty container for University') return def update(self, site, name, logger): pass