1 | ## $Id: department.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 | ## |
---|
18 | """University departments. |
---|
19 | """ |
---|
20 | import grok |
---|
21 | from zope.component import createObject |
---|
22 | from zope.component.interfaces import IFactory |
---|
23 | from zope.interface import implementedBy |
---|
24 | from waeup.sirp.university.interfaces import IDepartment, IDepartmentAdd |
---|
25 | from waeup.sirp.university.vocabularies import inst_types |
---|
26 | |
---|
27 | class Department(grok.Container): |
---|
28 | """A university department. |
---|
29 | """ |
---|
30 | grok.implements(IDepartment, IDepartmentAdd) |
---|
31 | |
---|
32 | @property # Make this method read_only and looking like an attr. |
---|
33 | def local_roles(cls): |
---|
34 | return ['waeup.local.DepartmentManager', |
---|
35 | 'waeup.local.ClearanceOfficer',] |
---|
36 | |
---|
37 | # A simple counter for ids. |
---|
38 | next_id = 0L |
---|
39 | |
---|
40 | def __init__(self, |
---|
41 | title=u'Unnamed Department', |
---|
42 | title_prefix=u'department', |
---|
43 | code=u"NA", **kw): |
---|
44 | super(Department, self).__init__(**kw) |
---|
45 | self.title = title |
---|
46 | self.title_prefix = title_prefix |
---|
47 | self.code = code |
---|
48 | self.courses = createObject(u'waeup.CourseContainer') |
---|
49 | self.courses.__parent__ = self |
---|
50 | self.courses.__name__ = 'courses' |
---|
51 | self.certificates = createObject(u'waeup.CertificateContainer') |
---|
52 | self.certificates.__parent__ = self |
---|
53 | self.certificates.__name__ = 'certificates' |
---|
54 | |
---|
55 | def traverse(self, name): |
---|
56 | """Deliver appropriate containers, if someone wants to go to courses |
---|
57 | or departments. |
---|
58 | """ |
---|
59 | if name == 'courses': |
---|
60 | return self.courses |
---|
61 | elif name == 'certificates': |
---|
62 | return self.certificates |
---|
63 | return None |
---|
64 | |
---|
65 | def longtitle(self): |
---|
66 | return "%s %s (%s)" % ( |
---|
67 | inst_types.getTerm(self.title_prefix).title, |
---|
68 | self.title, self.code) |
---|
69 | |
---|
70 | |
---|
71 | class DepartmentFactory(grok.GlobalUtility): |
---|
72 | """A factory for department containers. |
---|
73 | """ |
---|
74 | grok.implements(IFactory) |
---|
75 | grok.name(u'waeup.Department') |
---|
76 | title = u"Create a new department.", |
---|
77 | description = u"This factory instantiates new department instances." |
---|
78 | |
---|
79 | def __call__(self, *args, **kw): |
---|
80 | return Department(*args, **kw) |
---|
81 | |
---|
82 | def getInterfaces(self): |
---|
83 | """Get interfaces of objects provided by this factory. |
---|
84 | """ |
---|
85 | return implementedBy(Department) |
---|