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

Last change on this file since 13365 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
Line 
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##
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", **kw):
66        super(Department, self).__init__(**kw)
67        self.title = title
68        self.title_prefix = title_prefix
69        self.code = code
70        self.courses = CoursesContainer()
71        self.courses.__parent__ = self
72        self.courses.__name__ = 'courses'
73        self.certificates = CertificatesContainer()
74        self.certificates.__parent__ = self
75        self.certificates.__name__ = 'certificates'
76        self.score_editing_disabled = False
77
78    def traverse(self, name):
79        """Deliver appropriate containers, if someone wants to go to courses,
80        certificates or exports.
81        """
82        if name == 'courses':
83            return self.courses
84        elif name == 'certificates':
85            return self.certificates
86        elif name == 'exports':
87            # create a virtual exports container and return it
88            container = VirtualDepartmentExportJobContainer()
89            zope.location.location.located(container, self, 'exports')
90            return container
91        return None
92
93    @property
94    def longtitle(self):
95        return longtitle(self)
96
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
103        newfac = grok.getSite()['faculties'][facname]
104        oldcode = self.code
105        oldfac = self.__parent__
106        newfac[depname] = self
107        del oldfac[oldcode]
108        newfac[depname].code = depname
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
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)
133
134class DepartmentsPlugin(grok.GlobalUtility):
135    """A plugin that updates departments.
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.