[7195] | 1 | ## $Id: facultiescontainer.py 7819 2012-03-08 22:28:46Z 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 |
---|
[7819] | 21 | from waeup.kofa.interfaces import IKofaPluggable |
---|
[7811] | 22 | from waeup.kofa.university.interfaces import IFacultiesContainer, IFaculty |
---|
[3526] | 23 | |
---|
[7333] | 24 | class FacultiesContainer(grok.Container): |
---|
[4789] | 25 | """See interfaces for description. |
---|
| 26 | """ |
---|
[7333] | 27 | grok.implements(IFacultiesContainer) |
---|
[4789] | 28 | grok.require('waeup.manageUniversity') |
---|
| 29 | |
---|
| 30 | def addFaculty(self, faculty): |
---|
| 31 | if not IFaculty.providedBy(faculty): |
---|
[7725] | 32 | raise TypeError( |
---|
| 33 | 'FacultiesContainers contain only IFaculty instances') |
---|
[4789] | 34 | self[faculty.code] = faculty |
---|
| 35 | return |
---|
| 36 | |
---|
[7333] | 37 | class FacultiesContainerFactory(grok.GlobalUtility): |
---|
[4789] | 38 | """A factory for faculty containers. |
---|
| 39 | """ |
---|
| 40 | grok.implements(IFactory) |
---|
[7333] | 41 | grok.name(u'waeup.FacultiesContainer') |
---|
| 42 | title = u"Create a new facultiescontainer.", |
---|
| 43 | description = u"This factory instantiates new containers for faculties." |
---|
[4789] | 44 | |
---|
[4976] | 45 | def __call__(self, *args, **kw): |
---|
[7333] | 46 | return FacultiesContainer(*args, **kw) |
---|
[4789] | 47 | |
---|
| 48 | def getInterfaces(self): |
---|
[7333] | 49 | return implementedBy(FacultiesContainer) |
---|
[5014] | 50 | |
---|
| 51 | class AcademicsPlugin(grok.GlobalUtility): |
---|
[7333] | 52 | """A plugin that creates container for faculties inside a university. |
---|
[5014] | 53 | """ |
---|
[7819] | 54 | grok.implements(IKofaPluggable) |
---|
[5070] | 55 | grok.name('faculties') |
---|
[5014] | 56 | |
---|
[5070] | 57 | def setup(self, site, name, logger): |
---|
| 58 | if 'faculties' in site.keys(): |
---|
[7819] | 59 | logger.warn('Could not create container for faculties in Kofa.') |
---|
[5070] | 60 | return |
---|
[7333] | 61 | site['faculties'] = FacultiesContainer() |
---|
| 62 | logger.info('Container for faculties created') |
---|
[5070] | 63 | return |
---|
[5014] | 64 | |
---|
[5070] | 65 | def update(self, site, name, logger): |
---|
[6575] | 66 | if not 'faculties' in site.keys(): |
---|
| 67 | self.setup(site, name, logger) |
---|
| 68 | |
---|