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

Last change on this file since 15279 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
Line 
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##
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.CourseAdviser100',
52        'waeup.local.CourseAdviser200',
53        'waeup.local.CourseAdviser300',
54        'waeup.local.CourseAdviser400',
55        'waeup.local.CourseAdviser500',
56        'waeup.local.CourseAdviser600',
57        'waeup.local.CourseAdviser700',
58        'waeup.local.CourseAdviser800',
59        'waeup.local.LocalStudentsManager',
60        'waeup.local.Lecturer',
61        ]
62
63    def __init__(self,
64                 title=u'Unnamed Department',
65                 title_prefix=u'department',
66                 code=u"NA",
67                 officer_1=None,
68                 officer_2=None,
69                 officer_3=None,
70                 officer_4=None,
71                 **kw):
72        super(Department, self).__init__(**kw)
73        self.title = title
74        self.title_prefix = title_prefix
75        self.officer_1 = officer_1
76        self.officer_2 = officer_2
77        self.officer_3 = officer_3
78        self.officer_4 = officer_4
79        self.code = code
80        self.courses = CoursesContainer()
81        self.courses.__parent__ = self
82        self.courses.__name__ = 'courses'
83        self.certificates = CertificatesContainer()
84        self.certificates.__parent__ = self
85        self.certificates.__name__ = 'certificates'
86        self.score_editing_disabled = False
87
88    def traverse(self, name):
89        """Deliver appropriate containers, if someone wants to go to courses,
90        certificates or exports.
91        """
92        if name == 'courses':
93            return self.courses
94        elif name == 'certificates':
95            return self.certificates
96        elif name == 'exports':
97            # create a virtual exports container and return it
98            container = VirtualDepartmentExportJobContainer()
99            zope.location.location.located(container, self, 'exports')
100            return container
101        return None
102
103    @property
104    def longtitle(self):
105        return longtitle(self)
106
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
113        newfac = grok.getSite()['faculties'][facname]
114        oldcode = self.code
115        oldfac = self.__parent__
116        newfac[depname] = self
117        del oldfac[oldcode]
118        newfac[depname].code = depname
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
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)
143
144class DepartmentsPlugin(grok.GlobalUtility):
145    """A plugin that updates departments.
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.