[7195] | 1 | ## $Id: faculty.py 10561 2013-08-29 15:11:14Z 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 |
---|
[7681] | 24 | from zope.component import getUtility |
---|
[7819] | 25 | from waeup.kofa.interfaces import IKofaUtils |
---|
[7811] | 26 | from waeup.kofa.university.interfaces import ( |
---|
[5953] | 27 | IFaculty, IFacultyAdd, IDepartment) |
---|
[3526] | 28 | |
---|
[10561] | 29 | def longtitle(inst): |
---|
| 30 | insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT |
---|
| 31 | if inst.title_prefix == 'none': |
---|
| 32 | return "%s (%s)" % (inst.title, inst.code) |
---|
| 33 | return "%s %s (%s)" % ( |
---|
| 34 | insttypes_dict[inst.title_prefix], |
---|
| 35 | inst.title, inst.code) |
---|
| 36 | |
---|
[4789] | 37 | class Faculty(grok.Container): |
---|
| 38 | """A university faculty. |
---|
| 39 | """ |
---|
[5953] | 40 | grok.implements(IFaculty, IFacultyAdd) |
---|
[3526] | 41 | |
---|
[8993] | 42 | local_roles = [ |
---|
[10279] | 43 | 'waeup.local.DepartmentOfficer', |
---|
[8993] | 44 | 'waeup.local.DepartmentManager', |
---|
| 45 | 'waeup.local.ClearanceOfficer', |
---|
| 46 | 'waeup.local.UGClearanceOfficer', |
---|
| 47 | 'waeup.local.PGClearanceOfficer', |
---|
| 48 | 'waeup.local.CourseAdviser100', |
---|
| 49 | 'waeup.local.CourseAdviser200', |
---|
| 50 | 'waeup.local.CourseAdviser300', |
---|
| 51 | 'waeup.local.CourseAdviser400', |
---|
| 52 | 'waeup.local.CourseAdviser500', |
---|
| 53 | 'waeup.local.CourseAdviser600', |
---|
[10064] | 54 | 'waeup.local.CourseAdviser700', |
---|
| 55 | 'waeup.local.CourseAdviser800', |
---|
[8993] | 56 | ] |
---|
[6145] | 57 | |
---|
[4789] | 58 | def __init__(self, |
---|
| 59 | title=u'Unnamed Faculty', |
---|
| 60 | title_prefix=u'faculty', |
---|
| 61 | code=u'NA', **kw): |
---|
[3526] | 62 | super(Faculty, self).__init__(**kw) |
---|
[4789] | 63 | self.title = title |
---|
| 64 | self.title_prefix = title_prefix |
---|
| 65 | self.code = code |
---|
[3526] | 66 | |
---|
[4789] | 67 | def addDepartment(self, department): |
---|
| 68 | """Add a department to the faculty. |
---|
| 69 | """ |
---|
| 70 | if not IDepartment.providedBy(department): |
---|
| 71 | raise TypeError('Faculties contain only IDepartment instances') |
---|
| 72 | self[department.code] = department |
---|
[3526] | 73 | |
---|
[5988] | 74 | def longtitle(self): |
---|
[10561] | 75 | return longtitle(self) |
---|
[6145] | 76 | |
---|
[4789] | 77 | class FacultyFactory(grok.GlobalUtility): |
---|
| 78 | """A factory for faculty containers. |
---|
| 79 | """ |
---|
| 80 | grok.implements(IFactory) |
---|
| 81 | grok.name(u'waeup.Faculty') |
---|
| 82 | title = u"Create a new faculty.", |
---|
| 83 | description = u"This factory instantiates new faculty instances." |
---|
| 84 | |
---|
| 85 | def __call__(self, *args, **kw): |
---|
| 86 | return Faculty() |
---|
| 87 | |
---|
| 88 | def getInterfaces(self): |
---|
| 89 | return implementedBy(Faculty) |
---|