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 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): if not 'faculties' in site.keys(): self.setup(site, name, logger)