source: main/waeup.sirp/trunk/src/waeup/sirp/university/facultycontainer.py @ 4985

Last change on this file since 4985 was 4976, checked in by uli, 15 years ago

Factories must support variable keywords and args.

  • Property svn:eol-style set to native
File size: 1.3 KB
RevLine 
[3526]1import grok
[4789]2from zope.component.interfaces import IFactory
3from zope.interface import implementedBy
[4920]4from waeup.sirp.interfaces import IFacultyContainer, IFaculty
[3526]5
[4789]6class FacultyContainer(grok.Container):
7    """See interfaces for description.
8    """
9    grok.implements(IFacultyContainer)
10    grok.require('waeup.manageUniversity')
11
12    def addFaculty(self, faculty):
13        if not IFaculty.providedBy(faculty):
14            raise TypeError('FacultyContainers contain only IFaculty instances')
15        self[faculty.code] = faculty
16        return
17
18    def clear(self):
19        keys = self.keys()
20        for key in keys:
21            del self[key]
22
23    def getName(self, key):
24        if key in self.keys():
25            fac = self[key]
26            prefix = fac.title_prefix
27            prefix = prefix[0].upper() + prefix[1:]
28            return '%s of %s' % (prefix, fac.title)
29           
30class FacultyContainerFactory(grok.GlobalUtility):
31    """A factory for faculty containers.
32    """
33    grok.implements(IFactory)
34    grok.name(u'waeup.FacultyContainer')
35    title = u"Create a new faculty container.",
36    description = u"This factory instantiates new faculty containers."
37
[4976]38    def __call__(self, *args, **kw):
39        return FacultyContainer(*args, **kw)
[4789]40
41    def getInterfaces(self):
42        return implementedBy(FacultyContainer)
Note: See TracBrowser for help on using the repository browser.