1 | import grok |
---|
2 | from zope.component.interfaces import IFactory |
---|
3 | from zope.interface import implementedBy |
---|
4 | from waeup.sirp.university.interfaces import IFacultyContainer, IFaculty |
---|
5 | |
---|
6 | class 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 | |
---|
30 | class 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 | |
---|
38 | def __call__(self, *args, **kw): |
---|
39 | return FacultyContainer(*args, **kw) |
---|
40 | |
---|
41 | def getInterfaces(self): |
---|
42 | return implementedBy(FacultyContainer) |
---|