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

Last change on this file since 5016 was 5014, checked in by uli, 15 years ago

Provide a plugin for academics stuff.

  • Property svn:eol-style set to native
File size: 1.6 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 tells universities how to create a faculty container.
47    """
48    grok.implements(IWAeUPSIRPPluggable)
49
50    factory_name = u'waeup.FacultyContainer'
51    name = 'faculties'
52
Note: See TracBrowser for help on using the repository browser.