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 | class FacultyContainerFactory(grok.GlobalUtility): |
---|
20 | """A factory for faculty containers. |
---|
21 | """ |
---|
22 | grok.implements(IFactory) |
---|
23 | grok.name(u'waeup.FacultyContainer') |
---|
24 | title = u"Create a new faculty container.", |
---|
25 | description = u"This factory instantiates new faculty containers." |
---|
26 | |
---|
27 | def __call__(self, *args, **kw): |
---|
28 | return FacultyContainer(*args, **kw) |
---|
29 | |
---|
30 | def getInterfaces(self): |
---|
31 | return implementedBy(FacultyContainer) |
---|
32 | |
---|
33 | class AcademicsPlugin(grok.GlobalUtility): |
---|
34 | """A plugin that creates a faculty container inside a university. |
---|
35 | """ |
---|
36 | grok.implements(IWAeUPSIRPPluggable) |
---|
37 | grok.name('faculties') |
---|
38 | |
---|
39 | def setup(self, site, name, logger): |
---|
40 | if 'faculties' in site.keys(): |
---|
41 | logger.warn('Could not create faculty container in WAeUP SIRP.') |
---|
42 | return |
---|
43 | site['faculties'] = FacultyContainer() |
---|
44 | logger.info('Created faculty container for University') |
---|
45 | return |
---|
46 | |
---|
47 | def update(self, site, name, logger): |
---|
48 | if not 'faculties' in site.keys(): |
---|
49 | self.setup(site, name, logger) |
---|
50 | |
---|