source: main/waeup.sirp/branches/ulif-experimental-folders/src/waeup/sirp/university/coursecontainer.py @ 11107

Last change on this file since 11107 was 5005, checked in by uli, 15 years ago

Fix references to academics stuff interfaces. This is the first step to make academics stuff pluggable.

File size: 1.2 KB
Line 
1"""Course containers.
2"""
3import grok
4from zope.interface import implementedBy
5from zope.component.interfaces import IFactory
6from waeup.sirp.university.interfaces import ICourseContainer, ICourse
7
8class CourseContainer(grok.Container):
9    """See interfaces for description.
10    """
11    grok.implements(ICourseContainer)
12    grok.require('waeup.manageUniversity')
13
14    def addCourse(self, course):
15        """Add a course.
16        """
17        if not ICourse.providedBy(course):
18            raise TypeError('CourseContainers contain only ICourse instances')
19        self[course.code] = course
20        return
21
22    def clear(self):
23        """Remove all objects from course container.
24        """
25        keys = self.keys()
26        for key in keys:
27            del self[key]
28
29class CourseContainerFactory(grok.GlobalUtility):
30    """A factory for course containers.
31    """
32    grok.implements(IFactory)
33    grok.name(u'waeup.CourseContainer')
34    title = u"Create a new course container.",
35    description = u"This factory instantiates new course containers."
36
37    def __call__(self, *args, **kw):
38        return CourseContainer(*args, **kw)
39
40    def getInterfaces(self):
41        return implementedBy(CourseContainer)
Note: See TracBrowser for help on using the repository browser.