[7195] | 1 | ## $Id: faculty.py 14511 2017-02-07 08:33:05Z 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 | """Faculty components. |
---|
| 19 | """ |
---|
| 20 | |
---|
[3526] | 21 | import grok |
---|
[12632] | 22 | import zope.location.location |
---|
[4789] | 23 | from zope.component.interfaces import IFactory |
---|
| 24 | from zope.interface import implementedBy |
---|
[7681] | 25 | from zope.component import getUtility |
---|
[14511] | 26 | from zope.schema import getFields |
---|
| 27 | from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable |
---|
[12632] | 28 | from waeup.kofa.utils.batching import VirtualExportJobContainer |
---|
[7811] | 29 | from waeup.kofa.university.interfaces import ( |
---|
[10684] | 30 | IFaculty, IDepartment) |
---|
[3526] | 31 | |
---|
[10561] | 32 | def longtitle(inst): |
---|
| 33 | insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT |
---|
| 34 | if inst.title_prefix == 'none': |
---|
| 35 | return "%s (%s)" % (inst.title, inst.code) |
---|
| 36 | return "%s %s (%s)" % ( |
---|
| 37 | insttypes_dict[inst.title_prefix], |
---|
| 38 | inst.title, inst.code) |
---|
| 39 | |
---|
[12632] | 40 | class VirtualFacultyExportJobContainer(VirtualExportJobContainer): |
---|
| 41 | """A virtual export job container for facultiess. |
---|
| 42 | """ |
---|
| 43 | |
---|
[4789] | 44 | class Faculty(grok.Container): |
---|
| 45 | """A university faculty. |
---|
| 46 | """ |
---|
[10684] | 47 | grok.implements(IFaculty) |
---|
[3526] | 48 | |
---|
[8993] | 49 | local_roles = [ |
---|
[10279] | 50 | 'waeup.local.DepartmentOfficer', |
---|
[8993] | 51 | 'waeup.local.DepartmentManager', |
---|
| 52 | 'waeup.local.ClearanceOfficer', |
---|
| 53 | 'waeup.local.UGClearanceOfficer', |
---|
| 54 | 'waeup.local.PGClearanceOfficer', |
---|
| 55 | 'waeup.local.CourseAdviser100', |
---|
| 56 | 'waeup.local.CourseAdviser200', |
---|
| 57 | 'waeup.local.CourseAdviser300', |
---|
| 58 | 'waeup.local.CourseAdviser400', |
---|
| 59 | 'waeup.local.CourseAdviser500', |
---|
| 60 | 'waeup.local.CourseAdviser600', |
---|
[10064] | 61 | 'waeup.local.CourseAdviser700', |
---|
| 62 | 'waeup.local.CourseAdviser800', |
---|
[10639] | 63 | 'waeup.local.LocalStudentsManager', |
---|
| 64 | 'waeup.local.LocalWorkflowManager', |
---|
[8993] | 65 | ] |
---|
[6145] | 66 | |
---|
[4789] | 67 | def __init__(self, |
---|
| 68 | title=u'Unnamed Faculty', |
---|
| 69 | title_prefix=u'faculty', |
---|
[14511] | 70 | code=u'NA', |
---|
| 71 | officer_1=None, |
---|
| 72 | officer_2=None, |
---|
| 73 | **kw): |
---|
[3526] | 74 | super(Faculty, self).__init__(**kw) |
---|
[4789] | 75 | self.title = title |
---|
| 76 | self.title_prefix = title_prefix |
---|
| 77 | self.code = code |
---|
[14511] | 78 | self.officer_1 = officer_1 |
---|
| 79 | self.officer_2 = officer_2 |
---|
[3526] | 80 | |
---|
[12632] | 81 | def traverse(self, name): |
---|
| 82 | """Deliver appropriate containers. |
---|
| 83 | """ |
---|
| 84 | if name == 'exports': |
---|
| 85 | # create a virtual exports container and return it |
---|
| 86 | container = VirtualFacultyExportJobContainer() |
---|
| 87 | zope.location.location.located(container, self, 'exports') |
---|
| 88 | return container |
---|
| 89 | return None |
---|
| 90 | |
---|
[4789] | 91 | def addDepartment(self, department): |
---|
| 92 | """Add a department to the faculty. |
---|
| 93 | """ |
---|
| 94 | if not IDepartment.providedBy(department): |
---|
| 95 | raise TypeError('Faculties contain only IDepartment instances') |
---|
| 96 | self[department.code] = department |
---|
[3526] | 97 | |
---|
[10650] | 98 | @property |
---|
[5988] | 99 | def longtitle(self): |
---|
[10561] | 100 | return longtitle(self) |
---|
[6145] | 101 | |
---|
[4789] | 102 | class FacultyFactory(grok.GlobalUtility): |
---|
| 103 | """A factory for faculty containers. |
---|
| 104 | """ |
---|
| 105 | grok.implements(IFactory) |
---|
| 106 | grok.name(u'waeup.Faculty') |
---|
| 107 | title = u"Create a new faculty.", |
---|
| 108 | description = u"This factory instantiates new faculty instances." |
---|
| 109 | |
---|
| 110 | def __call__(self, *args, **kw): |
---|
| 111 | return Faculty() |
---|
| 112 | |
---|
| 113 | def getInterfaces(self): |
---|
| 114 | return implementedBy(Faculty) |
---|
[14511] | 115 | |
---|
| 116 | class FacultiesPlugin(grok.GlobalUtility): |
---|
| 117 | """A plugin that updates faculties. |
---|
| 118 | """ |
---|
| 119 | |
---|
| 120 | grok.implements(IKofaPluggable) |
---|
| 121 | grok.name('faculties') |
---|
| 122 | |
---|
| 123 | deprecated_attributes = [] |
---|
| 124 | |
---|
| 125 | def setup(self, site, name, logger): |
---|
| 126 | return |
---|
| 127 | |
---|
| 128 | def update(self, site, name, logger): |
---|
| 129 | items = getFields(IFaculty).items() |
---|
| 130 | for faculty in site['faculties'].values(): |
---|
| 131 | # Add new attributes |
---|
| 132 | for i in items: |
---|
| 133 | if not hasattr(faculty,i[0]): |
---|
| 134 | setattr(faculty,i[0],i[1].missing_value) |
---|
| 135 | logger.info( |
---|
| 136 | 'FacultiesPlugin: %s attribute %s added.' % ( |
---|
| 137 | faculty.code,i[0])) |
---|
| 138 | # Remove deprecated attributes |
---|
| 139 | for i in self.deprecated_attributes: |
---|
| 140 | try: |
---|
| 141 | delattr(faculty,i) |
---|
| 142 | logger.info( |
---|
| 143 | 'FacultiesPlugin: %s attribute %s deleted.' % ( |
---|
| 144 | faculty.code,i)) |
---|
| 145 | except AttributeError: |
---|
| 146 | pass |
---|
| 147 | return |
---|