[7195] | 1 | ## $Id: department.py 10279 2013-06-06 05:15:00Z 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 = [ |
---|
[10226] | 41 | 'waeup.local.ApplicationsManager', |
---|
[10279] | 42 | 'waeup.local.DepartmentOfficer', |
---|
[8993] | 43 | 'waeup.local.DepartmentManager', |
---|
| 44 | 'waeup.local.ClearanceOfficer', |
---|
| 45 | 'waeup.local.UGClearanceOfficer', |
---|
| 46 | 'waeup.local.PGClearanceOfficer', |
---|
| 47 | 'waeup.local.CourseAdviser100', |
---|
| 48 | 'waeup.local.CourseAdviser200', |
---|
| 49 | 'waeup.local.CourseAdviser300', |
---|
| 50 | 'waeup.local.CourseAdviser400', |
---|
| 51 | 'waeup.local.CourseAdviser500', |
---|
| 52 | 'waeup.local.CourseAdviser600', |
---|
[10064] | 53 | 'waeup.local.CourseAdviser700', |
---|
| 54 | 'waeup.local.CourseAdviser800', |
---|
[8993] | 55 | ] |
---|
[6152] | 56 | |
---|
[4789] | 57 | def __init__(self, |
---|
| 58 | title=u'Unnamed Department', |
---|
| 59 | title_prefix=u'department', |
---|
| 60 | code=u"NA", **kw): |
---|
| 61 | super(Department, self).__init__(**kw) |
---|
| 62 | self.title = title |
---|
| 63 | self.title_prefix = title_prefix |
---|
| 64 | self.code = code |
---|
[7681] | 65 | self.courses = CoursesContainer() |
---|
[4789] | 66 | self.courses.__parent__ = self |
---|
| 67 | self.courses.__name__ = 'courses' |
---|
[7681] | 68 | self.certificates = CertificatesContainer() |
---|
[4789] | 69 | self.certificates.__parent__ = self |
---|
| 70 | self.certificates.__name__ = 'certificates' |
---|
| 71 | |
---|
| 72 | def traverse(self, name): |
---|
| 73 | """Deliver appropriate containers, if someone wants to go to courses |
---|
| 74 | or departments. |
---|
| 75 | """ |
---|
| 76 | if name == 'courses': |
---|
| 77 | return self.courses |
---|
| 78 | elif name == 'certificates': |
---|
| 79 | return self.certificates |
---|
[9734] | 80 | elif name == 'exports': |
---|
| 81 | # create a virtual exports container and return it |
---|
[9797] | 82 | container = VirtualDepartmentExportJobContainer() |
---|
[9734] | 83 | zope.location.location.located(container, self, 'exports') |
---|
| 84 | return container |
---|
[4789] | 85 | return None |
---|
[6813] | 86 | |
---|
[5988] | 87 | def longtitle(self): |
---|
[7841] | 88 | insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT |
---|
[6813] | 89 | return "%s %s (%s)" % ( |
---|
[7681] | 90 | insttypes_dict[self.title_prefix], |
---|
[6813] | 91 | self.title, self.code) |
---|
[4789] | 92 | |
---|
| 93 | class DepartmentFactory(grok.GlobalUtility): |
---|
| 94 | """A factory for department containers. |
---|
| 95 | """ |
---|
| 96 | grok.implements(IFactory) |
---|
| 97 | grok.name(u'waeup.Department') |
---|
| 98 | title = u"Create a new department.", |
---|
| 99 | description = u"This factory instantiates new department instances." |
---|
| 100 | |
---|
| 101 | def __call__(self, *args, **kw): |
---|
| 102 | return Department(*args, **kw) |
---|
| 103 | |
---|
| 104 | def getInterfaces(self): |
---|
| 105 | """Get interfaces of objects provided by this factory. |
---|
| 106 | """ |
---|
| 107 | return implementedBy(Department) |
---|