[7195] | 1 | ## $Id: faculty.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 | ## |
---|
[4789] | 18 | """Faculty components. |
---|
| 19 | """ |
---|
| 20 | |
---|
[3526] | 21 | import grok |
---|
[4789] | 22 | from zope.component.interfaces import IFactory |
---|
| 23 | from zope.interface import implementedBy |
---|
[5953] | 24 | from waeup.sirp.university.interfaces import ( |
---|
| 25 | IFaculty, IFacultyAdd, IDepartment) |
---|
[6145] | 26 | from waeup.sirp.university.vocabularies import inst_types |
---|
[3526] | 27 | |
---|
[4789] | 28 | class Faculty(grok.Container): |
---|
| 29 | """A university faculty. |
---|
| 30 | """ |
---|
[5953] | 31 | grok.implements(IFaculty, IFacultyAdd) |
---|
[3526] | 32 | |
---|
[6145] | 33 | @property # Make this method read_only and looking like an attr. |
---|
| 34 | def local_roles(cls): |
---|
[7185] | 35 | return ['waeup.local.DepartmentManager', |
---|
[7153] | 36 | 'waeup.local.ClearanceOfficer',] |
---|
[6145] | 37 | |
---|
[4789] | 38 | def __init__(self, |
---|
| 39 | title=u'Unnamed Faculty', |
---|
| 40 | title_prefix=u'faculty', |
---|
| 41 | code=u'NA', **kw): |
---|
[3526] | 42 | super(Faculty, self).__init__(**kw) |
---|
[4789] | 43 | self.title = title |
---|
| 44 | self.title_prefix = title_prefix |
---|
| 45 | self.code = code |
---|
[3526] | 46 | |
---|
[4789] | 47 | def addDepartment(self, department): |
---|
| 48 | """Add a department to the faculty. |
---|
| 49 | """ |
---|
| 50 | if not IDepartment.providedBy(department): |
---|
| 51 | raise TypeError('Faculties contain only IDepartment instances') |
---|
| 52 | self[department.code] = department |
---|
[3526] | 53 | |
---|
[5988] | 54 | def longtitle(self): |
---|
[5994] | 55 | try: |
---|
| 56 | result = "%s %s (%s)" % ( |
---|
| 57 | inst_types.getTerm( |
---|
| 58 | self.title_prefix).title, |
---|
| 59 | self.title, self.code) |
---|
| 60 | except: |
---|
| 61 | result = "%s (%s)" % (self.title, self.code) |
---|
| 62 | return result |
---|
[6145] | 63 | |
---|
[4789] | 64 | class FacultyFactory(grok.GlobalUtility): |
---|
| 65 | """A factory for faculty containers. |
---|
| 66 | """ |
---|
| 67 | grok.implements(IFactory) |
---|
| 68 | grok.name(u'waeup.Faculty') |
---|
| 69 | title = u"Create a new faculty.", |
---|
| 70 | description = u"This factory instantiates new faculty instances." |
---|
| 71 | |
---|
| 72 | def __call__(self, *args, **kw): |
---|
| 73 | return Faculty() |
---|
| 74 | |
---|
| 75 | def getInterfaces(self): |
---|
| 76 | return implementedBy(Faculty) |
---|