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

Last change on this file since 10636 was 10635, checked in by Henrik Bettermann, 11 years ago

Using attrs_to_fields, which we didn't use in the beginning, makes a lot of problems. Many tests have to be changed and also the batch processor has to be adjusted. Thus it seems to be easier to use to update all department objects with the KofaPluggable? utility.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
RevLine 
[7195]1## $Id: department.py 10635 2013-09-21 09:12:09Z 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
[4789]22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
[7681]24from zope.component import getUtility
[10635]25from zope.schema import getFields
[10561]26from waeup.kofa.university.faculty import longtitle
[7811]27from waeup.kofa.university.coursescontainer import CoursesContainer
28from waeup.kofa.university.certificatescontainer import CertificatesContainer
[9734]29from waeup.kofa.utils.batching import VirtualExportJobContainer
[10635]30from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
[10634]31from waeup.kofa.utils.helpers import attrs_to_fields
[7811]32from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd
[4789]33
[9797]34class VirtualDepartmentExportJobContainer(VirtualExportJobContainer):
35    """A virtual export job container for departments.
36    """
37
[4789]38class Department(grok.Container):
39    """A university department.
40    """
[5953]41    grok.implements(IDepartment, IDepartmentAdd)
[4789]42
[8993]43    local_roles = [
[10226]44        'waeup.local.ApplicationsManager',
[10279]45        'waeup.local.DepartmentOfficer',
[8993]46        'waeup.local.DepartmentManager',
47        'waeup.local.ClearanceOfficer',
48        'waeup.local.UGClearanceOfficer',
49        'waeup.local.PGClearanceOfficer',
50        'waeup.local.CourseAdviser100',
51        'waeup.local.CourseAdviser200',
52        'waeup.local.CourseAdviser300',
53        'waeup.local.CourseAdviser400',
54        'waeup.local.CourseAdviser500',
55        'waeup.local.CourseAdviser600',
[10064]56        'waeup.local.CourseAdviser700',
57        'waeup.local.CourseAdviser800',
[8993]58        ]
[6152]59
[4789]60    def __init__(self,
61                 title=u'Unnamed Department',
62                 title_prefix=u'department',
63                 code=u"NA", **kw):
64        super(Department, self).__init__(**kw)
65        self.title = title
66        self.title_prefix = title_prefix
67        self.code = code
[7681]68        self.courses = CoursesContainer()
[4789]69        self.courses.__parent__ = self
70        self.courses.__name__ = 'courses'
[7681]71        self.certificates = CertificatesContainer()
[4789]72        self.certificates.__parent__ = self
73        self.certificates.__name__ = 'certificates'
[10635]74        self.score_editing_disabled = False
[4789]75
76    def traverse(self, name):
77        """Deliver appropriate containers, if someone wants to go to courses
78        or departments.
79        """
80        if name == 'courses':
81            return self.courses
82        elif name == 'certificates':
83            return self.certificates
[9734]84        elif name == 'exports':
85            # create a virtual exports container and return it
[9797]86            container = VirtualDepartmentExportJobContainer()
[9734]87            zope.location.location.located(container, self, 'exports')
88            return container
[4789]89        return None
[6813]90
[5988]91    def longtitle(self):
[10561]92        return longtitle(self)
[4789]93
94class DepartmentFactory(grok.GlobalUtility):
95    """A factory for department containers.
96    """
97    grok.implements(IFactory)
98    grok.name(u'waeup.Department')
99    title = u"Create a new department.",
100    description = u"This factory instantiates new department instances."
101
102    def __call__(self, *args, **kw):
103        return Department(*args, **kw)
104
105    def getInterfaces(self):
106        """Get interfaces of objects provided by this factory.
107        """
108        return implementedBy(Department)
[10635]109
110class DepartmentsPlugin(grok.GlobalUtility):
111    """A plugin that updates courses.
112    """
113
114    grok.implements(IKofaPluggable)
115    grok.name('departments')
116
117    deprecated_attributes = []
118
119    def setup(self, site, name, logger):
120        return
121
122    def update(self, site, name, logger):
123        items = getFields(IDepartment).items()
124        for faculty in site['faculties'].values():
125            for department in faculty.values():
126                # Add new attributes
127                for i in items:
128                    if not hasattr(department,i[0]):
129                        setattr(department,i[0],i[1].missing_value)
130                        logger.info(
131                            'DepartmentsPlugin: %s attribute %s added.' % (
132                            department.code,i[0]))
133                # Remove deprecated attributes
134                for i in self.deprecated_attributes:
135                    try:
136                        delattr(department,i)
137                        logger.info(
138                            'DepartmentsPlugin: %s attribute %s deleted.' % (
139                            department.code,i))
140                    except AttributeError:
141                        pass
142        return
Note: See TracBrowser for help on using the repository browser.