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

Last change on this file since 17669 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
Line 
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##
18"""University departments.
19"""
20import grok
21import zope.location.location
22from zope.event import notify
23from zope.catalog.interfaces import ICatalog
24from zope.component.interfaces import IFactory
25from zope.interface import implementedBy
26from zope.component import getUtility
27from zope.schema import getFields
28from waeup.kofa.university.faculty import longtitle
29from waeup.kofa.university.coursescontainer import CoursesContainer
30from waeup.kofa.university.certificatescontainer import CertificatesContainer
31from waeup.kofa.utils.batching import VirtualExportJobContainer
32from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
33from waeup.kofa.university.interfaces import IDepartment
34
35class VirtualDepartmentExportJobContainer(VirtualExportJobContainer):
36    """A virtual export job container for departments.
37    """
38
39class Department(grok.Container):
40    """A university department.
41    """
42    grok.implements(IDepartment)
43
44    local_roles = [
45        'waeup.local.ApplicationsManager',
46        'waeup.local.DepartmentOfficer',
47        'waeup.local.DepartmentManager',
48        'waeup.local.ClearanceOfficer',
49        'waeup.local.UGClearanceOfficer',
50        'waeup.local.PGClearanceOfficer',
51        'waeup.local.ReportsOfficer',
52        'waeup.local.CourseAdviser100',
53        'waeup.local.CourseAdviser200',
54        'waeup.local.CourseAdviser300',
55        'waeup.local.CourseAdviser400',
56        'waeup.local.CourseAdviser500',
57        'waeup.local.CourseAdviser600',
58        'waeup.local.CourseAdviser700',
59        'waeup.local.CourseAdviser800',
60        'waeup.local.LocalStudentsManager',
61        'waeup.local.Lecturer',
62        ]
63
64    def __init__(self,
65                 title=u'Unnamed Department',
66                 title_prefix=u'department',
67                 code=u"NA",
68                 officer_1=None,
69                 officer_2=None,
70                 officer_3=None,
71                 officer_4=None,
72                 **kw):
73        super(Department, self).__init__(**kw)
74        self.title = title
75        self.title_prefix = title_prefix
76        self.officer_1 = officer_1
77        self.officer_2 = officer_2
78        self.officer_3 = officer_3
79        self.officer_4 = officer_4
80        self.code = code
81        self.courses = CoursesContainer()
82        self.courses.__parent__ = self
83        self.courses.__name__ = 'courses'
84        self.certificates = CertificatesContainer()
85        self.certificates.__parent__ = self
86        self.certificates.__name__ = 'certificates'
87        self.score_editing_disabled = False
88
89    def traverse(self, name):
90        """Deliver appropriate containers, if someone wants to go to courses,
91        certificates or exports.
92        """
93        if name == 'courses':
94            return self.courses
95        elif name == 'certificates':
96            return self.certificates
97        elif name == 'exports':
98            # create a virtual exports container and return it
99            container = VirtualDepartmentExportJobContainer()
100            zope.location.location.located(container, self, 'exports')
101            return container
102        return None
103
104    @property
105    def longtitle(self):
106        return longtitle(self)
107
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
114        newfac = grok.getSite()['faculties'][facname]
115        oldcode = self.code
116        oldfac = self.__parent__
117        newfac[depname] = self
118        del oldfac[oldcode]
119        newfac[depname].code = depname
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
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)
144
145class DepartmentsPlugin(grok.GlobalUtility):
146    """A plugin that updates departments.
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.