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

Last change on this file since 16029 was 15968, checked in by Henrik Bettermann, 5 years ago

Add waeup.local.ReportsOfficer role.

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