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

Last change on this file since 14212 was 13212, checked in by Henrik Bettermann, 9 years ago

Fix some documentation errors.

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