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

Last change on this file since 12133 was 11891, checked in by Henrik Bettermann, 10 years ago

Enable localization of batch processing modules.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.2 KB
RevLine 
[7195]1## $Id: department.py 11891 2014-10-28 20:02:45Z 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
[10685]32from waeup.kofa.university.interfaces import IDepartment
[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    """
[10685]41    grok.implements(IDepartment)
[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',
[11891]58        'waeup.local.LocalStudentsManager',
[8993]59        ]
[6152]60
[4789]61    def __init__(self,
62                 title=u'Unnamed Department',
63                 title_prefix=u'department',
64                 code=u"NA", **kw):
65        super(Department, self).__init__(**kw)
66        self.title = title
67        self.title_prefix = title_prefix
68        self.code = code
[7681]69        self.courses = CoursesContainer()
[4789]70        self.courses.__parent__ = self
71        self.courses.__name__ = 'courses'
[7681]72        self.certificates = CertificatesContainer()
[4789]73        self.certificates.__parent__ = self
74        self.certificates.__name__ = 'certificates'
[10635]75        self.score_editing_disabled = False
[4789]76
77    def traverse(self, name):
78        """Deliver appropriate containers, if someone wants to go to courses
79        or departments.
80        """
81        if name == 'courses':
82            return self.courses
83        elif name == 'certificates':
84            return self.certificates
[9734]85        elif name == 'exports':
86            # create a virtual exports container and return it
[9797]87            container = VirtualDepartmentExportJobContainer()
[9734]88            zope.location.location.located(container, self, 'exports')
89            return container
[4789]90        return None
[6813]91
[10650]92    @property
[5988]93    def longtitle(self):
[10561]94        return longtitle(self)
[4789]95
96class DepartmentFactory(grok.GlobalUtility):
97    """A factory for department containers.
98    """
99    grok.implements(IFactory)
100    grok.name(u'waeup.Department')
101    title = u"Create a new department.",
102    description = u"This factory instantiates new department instances."
103
104    def __call__(self, *args, **kw):
105        return Department(*args, **kw)
106
107    def getInterfaces(self):
108        """Get interfaces of objects provided by this factory.
109        """
110        return implementedBy(Department)
[10635]111
112class DepartmentsPlugin(grok.GlobalUtility):
113    """A plugin that updates courses.
114    """
115
116    grok.implements(IKofaPluggable)
117    grok.name('departments')
118
119    deprecated_attributes = []
120
121    def setup(self, site, name, logger):
122        return
123
124    def update(self, site, name, logger):
125        items = getFields(IDepartment).items()
126        for faculty in site['faculties'].values():
127            for department in faculty.values():
128                # Add new attributes
129                for i in items:
130                    if not hasattr(department,i[0]):
131                        setattr(department,i[0],i[1].missing_value)
132                        logger.info(
133                            'DepartmentsPlugin: %s attribute %s added.' % (
134                            department.code,i[0]))
135                # Remove deprecated attributes
136                for i in self.deprecated_attributes:
137                    try:
138                        delattr(department,i)
139                        logger.info(
140                            'DepartmentsPlugin: %s attribute %s deleted.' % (
141                            department.code,i))
142                    except AttributeError:
143                        pass
144        return
Note: See TracBrowser for help on using the repository browser.