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