[7195] | 1 | ## $Id: department.py 10685 2013-11-02 09:02:26Z 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 |
---|
[10635] | 25 | from zope.schema import getFields |
---|
[10561] | 26 | from waeup.kofa.university.faculty import longtitle |
---|
[7811] | 27 | from waeup.kofa.university.coursescontainer import CoursesContainer |
---|
| 28 | from waeup.kofa.university.certificatescontainer import CertificatesContainer |
---|
[9734] | 29 | from waeup.kofa.utils.batching import VirtualExportJobContainer |
---|
[10635] | 30 | from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable |
---|
[10634] | 31 | from waeup.kofa.utils.helpers import attrs_to_fields |
---|
[10685] | 32 | from waeup.kofa.university.interfaces import IDepartment |
---|
[4789] | 33 | |
---|
[9797] | 34 | class VirtualDepartmentExportJobContainer(VirtualExportJobContainer): |
---|
| 35 | """A virtual export job container for departments. |
---|
| 36 | """ |
---|
| 37 | |
---|
[4789] | 38 | class Department(grok.Container): |
---|
| 39 | """A university department. |
---|
| 40 | """ |
---|
[10685] | 41 | grok.implements(IDepartment) |
---|
[4789] | 42 | |
---|
[8993] | 43 | local_roles = [ |
---|
[10226] | 44 | 'waeup.local.ApplicationsManager', |
---|
[10279] | 45 | 'waeup.local.DepartmentOfficer', |
---|
[8993] | 46 | 'waeup.local.DepartmentManager', |
---|
| 47 | 'waeup.local.ClearanceOfficer', |
---|
| 48 | 'waeup.local.UGClearanceOfficer', |
---|
| 49 | 'waeup.local.PGClearanceOfficer', |
---|
| 50 | 'waeup.local.CourseAdviser100', |
---|
| 51 | 'waeup.local.CourseAdviser200', |
---|
| 52 | 'waeup.local.CourseAdviser300', |
---|
| 53 | 'waeup.local.CourseAdviser400', |
---|
| 54 | 'waeup.local.CourseAdviser500', |
---|
| 55 | 'waeup.local.CourseAdviser600', |
---|
[10064] | 56 | 'waeup.local.CourseAdviser700', |
---|
| 57 | 'waeup.local.CourseAdviser800', |
---|
[8993] | 58 | ] |
---|
[6152] | 59 | |
---|
[4789] | 60 | def __init__(self, |
---|
| 61 | title=u'Unnamed Department', |
---|
| 62 | title_prefix=u'department', |
---|
| 63 | code=u"NA", **kw): |
---|
| 64 | super(Department, self).__init__(**kw) |
---|
| 65 | self.title = title |
---|
| 66 | self.title_prefix = title_prefix |
---|
| 67 | self.code = code |
---|
[7681] | 68 | self.courses = CoursesContainer() |
---|
[4789] | 69 | self.courses.__parent__ = self |
---|
| 70 | self.courses.__name__ = 'courses' |
---|
[7681] | 71 | self.certificates = CertificatesContainer() |
---|
[4789] | 72 | self.certificates.__parent__ = self |
---|
| 73 | self.certificates.__name__ = 'certificates' |
---|
[10635] | 74 | self.score_editing_disabled = False |
---|
[4789] | 75 | |
---|
| 76 | def traverse(self, name): |
---|
| 77 | """Deliver appropriate containers, if someone wants to go to courses |
---|
| 78 | or departments. |
---|
| 79 | """ |
---|
| 80 | if name == 'courses': |
---|
| 81 | return self.courses |
---|
| 82 | elif name == 'certificates': |
---|
| 83 | return self.certificates |
---|
[9734] | 84 | elif name == 'exports': |
---|
| 85 | # create a virtual exports container and return it |
---|
[9797] | 86 | container = VirtualDepartmentExportJobContainer() |
---|
[9734] | 87 | zope.location.location.located(container, self, 'exports') |
---|
| 88 | return container |
---|
[4789] | 89 | return None |
---|
[6813] | 90 | |
---|
[10650] | 91 | @property |
---|
[5988] | 92 | def longtitle(self): |
---|
[10561] | 93 | return longtitle(self) |
---|
[4789] | 94 | |
---|
| 95 | class DepartmentFactory(grok.GlobalUtility): |
---|
| 96 | """A factory for department containers. |
---|
| 97 | """ |
---|
| 98 | grok.implements(IFactory) |
---|
| 99 | grok.name(u'waeup.Department') |
---|
| 100 | title = u"Create a new department.", |
---|
| 101 | description = u"This factory instantiates new department instances." |
---|
| 102 | |
---|
| 103 | def __call__(self, *args, **kw): |
---|
| 104 | return Department(*args, **kw) |
---|
| 105 | |
---|
| 106 | def getInterfaces(self): |
---|
| 107 | """Get interfaces of objects provided by this factory. |
---|
| 108 | """ |
---|
| 109 | return implementedBy(Department) |
---|
[10635] | 110 | |
---|
| 111 | class DepartmentsPlugin(grok.GlobalUtility): |
---|
| 112 | """A plugin that updates courses. |
---|
| 113 | """ |
---|
| 114 | |
---|
| 115 | grok.implements(IKofaPluggable) |
---|
| 116 | grok.name('departments') |
---|
| 117 | |
---|
| 118 | deprecated_attributes = [] |
---|
| 119 | |
---|
| 120 | def setup(self, site, name, logger): |
---|
| 121 | return |
---|
| 122 | |
---|
| 123 | def update(self, site, name, logger): |
---|
| 124 | items = getFields(IDepartment).items() |
---|
| 125 | for faculty in site['faculties'].values(): |
---|
| 126 | for department in faculty.values(): |
---|
| 127 | # Add new attributes |
---|
| 128 | for i in items: |
---|
| 129 | if not hasattr(department,i[0]): |
---|
| 130 | setattr(department,i[0],i[1].missing_value) |
---|
| 131 | logger.info( |
---|
| 132 | 'DepartmentsPlugin: %s attribute %s added.' % ( |
---|
| 133 | department.code,i[0])) |
---|
| 134 | # Remove deprecated attributes |
---|
| 135 | for i in self.deprecated_attributes: |
---|
| 136 | try: |
---|
| 137 | delattr(department,i) |
---|
| 138 | logger.info( |
---|
| 139 | 'DepartmentsPlugin: %s attribute %s deleted.' % ( |
---|
| 140 | department.code,i)) |
---|
| 141 | except AttributeError: |
---|
| 142 | pass |
---|
| 143 | return |
---|