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

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

Remove other redundant interfaces, see previous revision.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.1 KB
Line 
1## $Id: department.py 10685 2013-11-02 09:02:26Z 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.component.interfaces import IFactory
23from zope.interface import implementedBy
24from zope.component import getUtility
25from zope.schema import getFields
26from waeup.kofa.university.faculty import longtitle
27from waeup.kofa.university.coursescontainer import CoursesContainer
28from waeup.kofa.university.certificatescontainer import CertificatesContainer
29from waeup.kofa.utils.batching import VirtualExportJobContainer
30from waeup.kofa.interfaces import IKofaUtils, IKofaPluggable
31from waeup.kofa.utils.helpers import attrs_to_fields
32from waeup.kofa.university.interfaces import IDepartment
33
34class VirtualDepartmentExportJobContainer(VirtualExportJobContainer):
35    """A virtual export job container for departments.
36    """
37
38class Department(grok.Container):
39    """A university department.
40    """
41    grok.implements(IDepartment)
42
43    local_roles = [
44        'waeup.local.ApplicationsManager',
45        'waeup.local.DepartmentOfficer',
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',
56        'waeup.local.CourseAdviser700',
57        'waeup.local.CourseAdviser800',
58        ]
59
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
68        self.courses = CoursesContainer()
69        self.courses.__parent__ = self
70        self.courses.__name__ = 'courses'
71        self.certificates = CertificatesContainer()
72        self.certificates.__parent__ = self
73        self.certificates.__name__ = 'certificates'
74        self.score_editing_disabled = False
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
84        elif name == 'exports':
85            # create a virtual exports container and return it
86            container = VirtualDepartmentExportJobContainer()
87            zope.location.location.located(container, self, 'exports')
88            return container
89        return None
90
91    @property
92    def longtitle(self):
93        return longtitle(self)
94
95class DepartmentFactory(grok.GlobalUtility):
96    """A factory for department containers.
97    """
98    grok.implements(IFactory)
99    grok.name(u'waeup.Department')
100    title = u"Create a new department.",
101    description = u"This factory instantiates new department instances."
102
103    def __call__(self, *args, **kw):
104        return Department(*args, **kw)
105
106    def getInterfaces(self):
107        """Get interfaces of objects provided by this factory.
108        """
109        return implementedBy(Department)
110
111class DepartmentsPlugin(grok.GlobalUtility):
112    """A plugin that updates courses.
113    """
114
115    grok.implements(IKofaPluggable)
116    grok.name('departments')
117
118    deprecated_attributes = []
119
120    def setup(self, site, name, logger):
121        return
122
123    def update(self, site, name, logger):
124        items = getFields(IDepartment).items()
125        for faculty in site['faculties'].values():
126            for department in faculty.values():
127                # Add new attributes
128                for i in items:
129                    if not hasattr(department,i[0]):
130                        setattr(department,i[0],i[1].missing_value)
131                        logger.info(
132                            'DepartmentsPlugin: %s attribute %s added.' % (
133                            department.code,i[0]))
134                # Remove deprecated attributes
135                for i in self.deprecated_attributes:
136                    try:
137                        delattr(department,i)
138                        logger.info(
139                            'DepartmentsPlugin: %s attribute %s deleted.' % (
140                            department.code,i))
141                    except AttributeError:
142                        pass
143        return
Note: See TracBrowser for help on using the repository browser.