[7195] | 1 | ## $Id: facultycontainer.py 7195 2011-11-25 07:34:07Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[3526] | 18 | import grok |
---|
[4789] | 19 | from zope.component.interfaces import IFactory |
---|
| 20 | from zope.interface import implementedBy |
---|
[5014] | 21 | from waeup.sirp.interfaces import IWAeUPSIRPPluggable |
---|
[5005] | 22 | from waeup.sirp.university.interfaces import IFacultyContainer, IFaculty |
---|
[3526] | 23 | |
---|
[4789] | 24 | class FacultyContainer(grok.Container): |
---|
| 25 | """See interfaces for description. |
---|
| 26 | """ |
---|
| 27 | grok.implements(IFacultyContainer) |
---|
| 28 | grok.require('waeup.manageUniversity') |
---|
| 29 | |
---|
| 30 | def addFaculty(self, faculty): |
---|
| 31 | if not IFaculty.providedBy(faculty): |
---|
| 32 | raise TypeError('FacultyContainers contain only IFaculty instances') |
---|
| 33 | self[faculty.code] = faculty |
---|
| 34 | return |
---|
| 35 | |
---|
| 36 | class FacultyContainerFactory(grok.GlobalUtility): |
---|
| 37 | """A factory for faculty containers. |
---|
| 38 | """ |
---|
| 39 | grok.implements(IFactory) |
---|
| 40 | grok.name(u'waeup.FacultyContainer') |
---|
| 41 | title = u"Create a new faculty container.", |
---|
| 42 | description = u"This factory instantiates new faculty containers." |
---|
| 43 | |
---|
[4976] | 44 | def __call__(self, *args, **kw): |
---|
| 45 | return FacultyContainer(*args, **kw) |
---|
[4789] | 46 | |
---|
| 47 | def getInterfaces(self): |
---|
| 48 | return implementedBy(FacultyContainer) |
---|
[5014] | 49 | |
---|
| 50 | class AcademicsPlugin(grok.GlobalUtility): |
---|
[5070] | 51 | """A plugin that creates a faculty container inside a university. |
---|
[5014] | 52 | """ |
---|
| 53 | grok.implements(IWAeUPSIRPPluggable) |
---|
[5070] | 54 | grok.name('faculties') |
---|
[5014] | 55 | |
---|
[5070] | 56 | def setup(self, site, name, logger): |
---|
| 57 | if 'faculties' in site.keys(): |
---|
| 58 | logger.warn('Could not create faculty container in WAeUP SIRP.') |
---|
| 59 | return |
---|
| 60 | site['faculties'] = FacultyContainer() |
---|
| 61 | logger.info('Created faculty container for University') |
---|
| 62 | return |
---|
[5014] | 63 | |
---|
[5070] | 64 | def update(self, site, name, logger): |
---|
[6575] | 65 | if not 'faculties' in site.keys(): |
---|
| 66 | self.setup(site, name, logger) |
---|
| 67 | |
---|