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