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

Last change on this file since 14657 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
RevLine 
[7195]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##
[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',
[8993]60        ]
[6152]61
[4789]62    def __init__(self,
63                 title=u'Unnamed Department',
64                 title_prefix=u'department',
[14511]65                 code=u"NA",
66                 officer_1=None,
67                 officer_2=None,
68                 officer_3=None,
69                 officer_4=None,
70                 **kw):
[4789]71        super(Department, self).__init__(**kw)
72        self.title = title
73        self.title_prefix = title_prefix
[14511]74        self.officer_1 = officer_1
75        self.officer_2 = officer_2
76        self.officer_3 = officer_3
77        self.officer_4 = officer_4
[4789]78        self.code = code
[7681]79        self.courses = CoursesContainer()
[4789]80        self.courses.__parent__ = self
81        self.courses.__name__ = 'courses'
[7681]82        self.certificates = CertificatesContainer()
[4789]83        self.certificates.__parent__ = self
84        self.certificates.__name__ = 'certificates'
[10635]85        self.score_editing_disabled = False
[4789]86
87    def traverse(self, name):
[12906]88        """Deliver appropriate containers, if someone wants to go to courses,
89        certificates or exports.
[4789]90        """
91        if name == 'courses':
92            return self.courses
93        elif name == 'certificates':
94            return self.certificates
[9734]95        elif name == 'exports':
96            # create a virtual exports container and return it
[9797]97            container = VirtualDepartmentExportJobContainer()
[9734]98            zope.location.location.located(container, self, 'exports')
99            return container
[4789]100        return None
[6813]101
[10650]102    @property
[5988]103    def longtitle(self):
[10561]104        return longtitle(self)
[4789]105
[12609]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
[12620]112        newfac = grok.getSite()['faculties'][facname]
[12609]113        oldcode = self.code
[12620]114        oldfac = self.__parent__
115        newfac[depname] = self
116        del oldfac[oldcode]
117        newfac[depname].code = depname
[12609]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
[4789]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)
[10635]142
143class DepartmentsPlugin(grok.GlobalUtility):
[13212]144    """A plugin that updates departments.
[10635]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.