source: main/waeup.sirp/branches/henrik-experimental-layout/src/waeup/sirp/university/facultycontainer.py @ 5352

Last change on this file since 5352 was 5070, checked in by uli, 15 years ago

Update faculty container plugin.

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1import grok
2from zope.component.interfaces import IFactory
3from zope.interface import implementedBy
4from waeup.sirp.interfaces import IWAeUPSIRPPluggable
5from waeup.sirp.university.interfaces import IFacultyContainer, IFaculty
6
7class FacultyContainer(grok.Container):
8    """See interfaces for description.
9    """
10    grok.implements(IFacultyContainer)
11    grok.require('waeup.manageUniversity')
12
13    def addFaculty(self, faculty):
14        if not IFaculty.providedBy(faculty):
15            raise TypeError('FacultyContainers contain only IFaculty instances')
16        self[faculty.code] = faculty
17        return
18
19    def clear(self):
20        keys = self.keys()
21        for key in keys:
22            del self[key]
23
24    def getName(self, key):
25        if key in self.keys():
26            fac = self[key]
27            prefix = fac.title_prefix
28            prefix = prefix[0].upper() + prefix[1:]
29            return '%s of %s' % (prefix, fac.title)
30           
31class FacultyContainerFactory(grok.GlobalUtility):
32    """A factory for faculty containers.
33    """
34    grok.implements(IFactory)
35    grok.name(u'waeup.FacultyContainer')
36    title = u"Create a new faculty container.",
37    description = u"This factory instantiates new faculty containers."
38
39    def __call__(self, *args, **kw):
40        return FacultyContainer(*args, **kw)
41
42    def getInterfaces(self):
43        return implementedBy(FacultyContainer)
44
45class AcademicsPlugin(grok.GlobalUtility):
46    """A plugin that creates a faculty container inside a university.
47    """
48    grok.implements(IWAeUPSIRPPluggable)
49    grok.name('faculties')
50
51    def setup(self, site, name, logger):
52        if 'faculties' in site.keys():
53            logger.warn('Could not create faculty container in WAeUP SIRP.')
54            return
55        site['faculties'] = FacultyContainer()
56        logger.info('Created faculty container for University')
57        return
58
59    def update(self, site, name, logger):
60        pass
Note: See TracBrowser for help on using the repository browser.