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

Last change on this file since 14934 was 14511, checked in by Henrik Bettermann, 8 years ago

Add officer name fields do IDepartment and IFaculty. Plugins must be updated!

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