source: main/waeup.kofa/trunk/src/waeup/kofa/university/department.py @ 15610

Last change on this file since 15610 was 14992, checked in by Henrik Bettermann, 7 years ago

Allow lecturer role assignment also at department level.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.2 KB
RevLine 
[7195]1## $Id: department.py 14992 2018-04-26 08:50:56Z 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"""
20import grok
[9734]21import zope.location.location
[12609]22from zope.event import notify
23from zope.catalog.interfaces import ICatalog
[4789]24from zope.component.interfaces import IFactory
25from zope.interface import implementedBy
[7681]26from zope.component import getUtility
[10635]27from zope.schema import getFields
[10561]28from waeup.kofa.university.faculty import longtitle
[7811]29from waeup.kofa.university.coursescontainer import CoursesContainer
30from waeup.kofa.university.certificatescontainer import CertificatesContainer
[9734]31from waeup.kofa.utils.batching import VirtualExportJobContainer
[10635]32from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
[10685]33from waeup.kofa.university.interfaces import IDepartment
[4789]34
[9797]35class VirtualDepartmentExportJobContainer(VirtualExportJobContainer):
36    """A virtual export job container for departments.
37    """
38
[4789]39class Department(grok.Container):
40    """A university department.
41    """
[10685]42    grok.implements(IDepartment)
[4789]43
[8993]44    local_roles = [
[10226]45        'waeup.local.ApplicationsManager',
[10279]46        'waeup.local.DepartmentOfficer',
[8993]47        'waeup.local.DepartmentManager',
48        'waeup.local.ClearanceOfficer',
49        'waeup.local.UGClearanceOfficer',
50        'waeup.local.PGClearanceOfficer',
51        'waeup.local.CourseAdviser100',
52        'waeup.local.CourseAdviser200',
53        'waeup.local.CourseAdviser300',
54        'waeup.local.CourseAdviser400',
55        'waeup.local.CourseAdviser500',
56        'waeup.local.CourseAdviser600',
[10064]57        'waeup.local.CourseAdviser700',
58        'waeup.local.CourseAdviser800',
[11891]59        'waeup.local.LocalStudentsManager',
[14992]60        'waeup.local.Lecturer',
[8993]61        ]
[6152]62
[4789]63    def __init__(self,
64                 title=u'Unnamed Department',
65                 title_prefix=u'department',
[14511]66                 code=u"NA",
67                 officer_1=None,
68                 officer_2=None,
69                 officer_3=None,
70                 officer_4=None,
71                 **kw):
[4789]72        super(Department, self).__init__(**kw)
73        self.title = title
74        self.title_prefix = title_prefix
[14511]75        self.officer_1 = officer_1
76        self.officer_2 = officer_2
77        self.officer_3 = officer_3
78        self.officer_4 = officer_4
[4789]79        self.code = code
[7681]80        self.courses = CoursesContainer()
[4789]81        self.courses.__parent__ = self
82        self.courses.__name__ = 'courses'
[7681]83        self.certificates = CertificatesContainer()
[4789]84        self.certificates.__parent__ = self
85        self.certificates.__name__ = 'certificates'
[10635]86        self.score_editing_disabled = False
[4789]87
88    def traverse(self, name):
[12906]89        """Deliver appropriate containers, if someone wants to go to courses,
90        certificates or exports.
[4789]91        """
92        if name == 'courses':
93            return self.courses
94        elif name == 'certificates':
95            return self.certificates
[9734]96        elif name == 'exports':
97            # create a virtual exports container and return it
[9797]98            container = VirtualDepartmentExportJobContainer()
[9734]99            zope.location.location.located(container, self, 'exports')
100            return container
[4789]101        return None
[6813]102
[10650]103    @property
[5988]104    def longtitle(self):
[10561]105        return longtitle(self)
[4789]106
[12609]107    def moveDepartment(self, facname, depname):
108        """ Move department to new department named depname in
109        faculty named facname.
110
111        """
112        self.moved = True
[12620]113        newfac = grok.getSite()['faculties'][facname]
[12609]114        oldcode = self.code
[12620]115        oldfac = self.__parent__
116        newfac[depname] = self
117        del oldfac[oldcode]
118        newfac[depname].code = depname
[12609]119        #self.__parent__._p_changed = True
120        cat = getUtility(ICatalog, name='students_catalog')
121        results = cat.searchResults(depcode=(oldcode, oldcode))
122        for student in results:
123            notify(grok.ObjectModifiedEvent(student))
124            student.__parent__.logger.info(
125                '%s - Department moved' % student.__name__)
126        return
127
[4789]128class DepartmentFactory(grok.GlobalUtility):
129    """A factory for department containers.
130    """
131    grok.implements(IFactory)
132    grok.name(u'waeup.Department')
133    title = u"Create a new department.",
134    description = u"This factory instantiates new department instances."
135
136    def __call__(self, *args, **kw):
137        return Department(*args, **kw)
138
139    def getInterfaces(self):
140        """Get interfaces of objects provided by this factory.
141        """
142        return implementedBy(Department)
[10635]143
144class DepartmentsPlugin(grok.GlobalUtility):
[13212]145    """A plugin that updates departments.
[10635]146    """
147
148    grok.implements(IKofaPluggable)
149    grok.name('departments')
150
151    deprecated_attributes = []
152
153    def setup(self, site, name, logger):
154        return
155
156    def update(self, site, name, logger):
157        items = getFields(IDepartment).items()
158        for faculty in site['faculties'].values():
159            for department in faculty.values():
160                # Add new attributes
161                for i in items:
162                    if not hasattr(department,i[0]):
163                        setattr(department,i[0],i[1].missing_value)
164                        logger.info(
165                            'DepartmentsPlugin: %s attribute %s added.' % (
166                            department.code,i[0]))
167                # Remove deprecated attributes
168                for i in self.deprecated_attributes:
169                    try:
170                        delattr(department,i)
171                        logger.info(
172                            'DepartmentsPlugin: %s attribute %s deleted.' % (
173                            department.code,i))
174                    except AttributeError:
175                        pass
176        return
Note: See TracBrowser for help on using the repository browser.