[7195] | 1 | ## $Id: department.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 | ## |
---|
[4789] | 18 | """University departments. |
---|
| 19 | """ |
---|
| 20 | import grok |
---|
[9734] | 21 | import zope.location.location |
---|
[4789] | 22 | from zope.component.interfaces import IFactory |
---|
| 23 | from zope.interface import implementedBy |
---|
[7681] | 24 | from zope.component import getUtility |
---|
[7811] | 25 | from waeup.kofa.university.coursescontainer import CoursesContainer |
---|
| 26 | from waeup.kofa.university.certificatescontainer import CertificatesContainer |
---|
[9734] | 27 | from waeup.kofa.utils.batching import VirtualExportJobContainer |
---|
[7819] | 28 | from waeup.kofa.interfaces import IKofaUtils |
---|
[7811] | 29 | from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd |
---|
[4789] | 30 | |
---|
[9797] | 31 | class VirtualDepartmentExportJobContainer(VirtualExportJobContainer): |
---|
| 32 | """A virtual export job container for departments. |
---|
| 33 | """ |
---|
| 34 | |
---|
[4789] | 35 | class Department(grok.Container): |
---|
| 36 | """A university department. |
---|
| 37 | """ |
---|
[5953] | 38 | grok.implements(IDepartment, IDepartmentAdd) |
---|
[4789] | 39 | |
---|
[8993] | 40 | local_roles = [ |
---|
| 41 | 'waeup.local.DepartmentManager', |
---|
| 42 | 'waeup.local.ClearanceOfficer', |
---|
| 43 | 'waeup.local.UGClearanceOfficer', |
---|
| 44 | 'waeup.local.PGClearanceOfficer', |
---|
| 45 | 'waeup.local.CourseAdviser100', |
---|
| 46 | 'waeup.local.CourseAdviser200', |
---|
| 47 | 'waeup.local.CourseAdviser300', |
---|
| 48 | 'waeup.local.CourseAdviser400', |
---|
| 49 | 'waeup.local.CourseAdviser500', |
---|
| 50 | 'waeup.local.CourseAdviser600', |
---|
[10064] | 51 | 'waeup.local.CourseAdviser700', |
---|
| 52 | 'waeup.local.CourseAdviser800', |
---|
[8993] | 53 | ] |
---|
[6152] | 54 | |
---|
[4789] | 55 | def __init__(self, |
---|
| 56 | title=u'Unnamed Department', |
---|
| 57 | title_prefix=u'department', |
---|
| 58 | code=u"NA", **kw): |
---|
| 59 | super(Department, self).__init__(**kw) |
---|
| 60 | self.title = title |
---|
| 61 | self.title_prefix = title_prefix |
---|
| 62 | self.code = code |
---|
[7681] | 63 | self.courses = CoursesContainer() |
---|
[4789] | 64 | self.courses.__parent__ = self |
---|
| 65 | self.courses.__name__ = 'courses' |
---|
[7681] | 66 | self.certificates = CertificatesContainer() |
---|
[4789] | 67 | self.certificates.__parent__ = self |
---|
| 68 | self.certificates.__name__ = 'certificates' |
---|
| 69 | |
---|
| 70 | def traverse(self, name): |
---|
| 71 | """Deliver appropriate containers, if someone wants to go to courses |
---|
| 72 | or departments. |
---|
| 73 | """ |
---|
| 74 | if name == 'courses': |
---|
| 75 | return self.courses |
---|
| 76 | elif name == 'certificates': |
---|
| 77 | return self.certificates |
---|
[9734] | 78 | elif name == 'exports': |
---|
| 79 | # create a virtual exports container and return it |
---|
[9797] | 80 | container = VirtualDepartmentExportJobContainer() |
---|
[9734] | 81 | zope.location.location.located(container, self, 'exports') |
---|
| 82 | return container |
---|
[4789] | 83 | return None |
---|
[6813] | 84 | |
---|
[5988] | 85 | def longtitle(self): |
---|
[7841] | 86 | insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT |
---|
[6813] | 87 | return "%s %s (%s)" % ( |
---|
[7681] | 88 | insttypes_dict[self.title_prefix], |
---|
[6813] | 89 | self.title, self.code) |
---|
[4789] | 90 | |
---|
| 91 | class DepartmentFactory(grok.GlobalUtility): |
---|
| 92 | """A factory for department containers. |
---|
| 93 | """ |
---|
| 94 | grok.implements(IFactory) |
---|
| 95 | grok.name(u'waeup.Department') |
---|
| 96 | title = u"Create a new department.", |
---|
| 97 | description = u"This factory instantiates new department instances." |
---|
| 98 | |
---|
| 99 | def __call__(self, *args, **kw): |
---|
| 100 | return Department(*args, **kw) |
---|
| 101 | |
---|
| 102 | def getInterfaces(self): |
---|
| 103 | """Get interfaces of objects provided by this factory. |
---|
| 104 | """ |
---|
| 105 | return implementedBy(Department) |
---|