"""Course containers. """ import grok from zope.interface import implementedBy from zope.component.interfaces import IFactory from waeup.interfaces import ICourseContainer, ICourse class CourseContainer(grok.Container): """See interfaces for description. """ grok.implements(ICourseContainer) grok.require('waeup.manageUniversity') def addCourse(self, course): """Add a course. """ if not ICourse.providedBy(course): raise TypeError('CourseContainers contain only ICourse instances') self[course.code] = course return def clear(self): """Remove all objects from course container. """ keys = self.keys() for key in keys: del self[key] class CourseContainerFactory(grok.GlobalUtility): """A factory for course containers. """ grok.implements(IFactory) grok.name(u'waeup.CourseContainer') title = u"Create a new course container.", description = u"This factory instantiates new course containers." def __call__(self, *args, **kw): return CourseContainer(*args, **kw) def getInterfaces(self): return implementedBy(CourseContainer)