1 | import grok |
---|
2 | from zope.component.interfaces import IFactory |
---|
3 | from zope.interface import implementedBy |
---|
4 | from waeup.sirp.interfaces import IWAeUPSIRPPluggable |
---|
5 | from waeup.sirp.university.interfaces import IFacultyContainer, IFaculty |
---|
6 | |
---|
7 | class 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 | |
---|
31 | class 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 | |
---|
45 | class 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 | |
---|