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
RevLine 
[7195]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##
[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
[7811]25from waeup.kofa.university.coursescontainer import CoursesContainer
26from waeup.kofa.university.certificatescontainer import CertificatesContainer
[9734]27from waeup.kofa.utils.batching import VirtualExportJobContainer
[7819]28from waeup.kofa.interfaces import IKofaUtils
[7811]29from waeup.kofa.university.interfaces import IDepartment, IDepartmentAdd
[4789]30
[9797]31class VirtualDepartmentExportJobContainer(VirtualExportJobContainer):
32    """A virtual export job container for departments.
33    """
34
[4789]35class Department(grok.Container):
36    """A university department.
37    """
[5953]38    grok.implements(IDepartment, IDepartmentAdd)
[4789]39
[8993]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        ]
[6152]52
[4789]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
[7681]61        self.courses = CoursesContainer()
[4789]62        self.courses.__parent__ = self
63        self.courses.__name__ = 'courses'
[7681]64        self.certificates = CertificatesContainer()
[4789]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
[9734]76        elif name == 'exports':
77            # create a virtual exports container and return it
[9797]78            container = VirtualDepartmentExportJobContainer()
[9734]79            zope.location.location.located(container, self, 'exports')
80            return container
[4789]81        return None
[6813]82
[5988]83    def longtitle(self):
[7841]84        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
[6813]85        return "%s %s (%s)" % (
[7681]86            insttypes_dict[self.title_prefix],
[6813]87            self.title, self.code)
[4789]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.