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

Last change on this file since 9826 was 9797, checked in by uli, 12 years ago

Local exports for departments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1## $Id: department.py 9797 2012-12-13 15:39:31Z uli $
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 waeup.kofa.university.coursescontainer import CoursesContainer
26from waeup.kofa.university.certificatescontainer import CertificatesContainer
27from waeup.kofa.utils.batching import VirtualExportJobContainer
28from waeup.kofa.interfaces import IKofaUtils
29from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd
30
31class VirtualDepartmentExportJobContainer(VirtualExportJobContainer):
32    """A virtual export job container for departments.
33    """
34
35class Department(grok.Container):
36    """A university department.
37    """
38    grok.implements(IDepartment, IDepartmentAdd)
39
40    local_roles = [
41        'waeup.local.DepartmentManager',
42        'waeup.local.ClearanceOfficer',
43        'waeup.local.UGClearanceOfficer',
44        'waeup.local.PGClearanceOfficer',
45        'waeup.local.CourseAdviser100',
46        'waeup.local.CourseAdviser200',
47        'waeup.local.CourseAdviser300',
48        'waeup.local.CourseAdviser400',
49        'waeup.local.CourseAdviser500',
50        'waeup.local.CourseAdviser600',
51        ]
52
53    def __init__(self,
54                 title=u'Unnamed Department',
55                 title_prefix=u'department',
56                 code=u"NA", **kw):
57        super(Department, self).__init__(**kw)
58        self.title = title
59        self.title_prefix = title_prefix
60        self.code = code
61        self.courses = CoursesContainer()
62        self.courses.__parent__ = self
63        self.courses.__name__ = 'courses'
64        self.certificates = CertificatesContainer()
65        self.certificates.__parent__ = self
66        self.certificates.__name__ = 'certificates'
67
68    def traverse(self, name):
69        """Deliver appropriate containers, if someone wants to go to courses
70        or departments.
71        """
72        if name == 'courses':
73            return self.courses
74        elif name == 'certificates':
75            return self.certificates
76        elif name == 'exports':
77            # create a virtual exports container and return it
78            container = VirtualDepartmentExportJobContainer()
79            zope.location.location.located(container, self, 'exports')
80            return container
81        return None
82
83    def longtitle(self):
84        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
85        return "%s %s (%s)" % (
86            insttypes_dict[self.title_prefix],
87            self.title, self.code)
88
89class DepartmentFactory(grok.GlobalUtility):
90    """A factory for department containers.
91    """
92    grok.implements(IFactory)
93    grok.name(u'waeup.Department')
94    title = u"Create a new department.",
95    description = u"This factory instantiates new department instances."
96
97    def __call__(self, *args, **kw):
98        return Department(*args, **kw)
99
100    def getInterfaces(self):
101        """Get interfaces of objects provided by this factory.
102        """
103        return implementedBy(Department)
Note: See TracBrowser for help on using the repository browser.