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

Last change on this file since 10252 was 10226, checked in by Henrik Bettermann, 12 years ago

Add local and global ApplicationsManager? role. Assign role dynamically.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
RevLine 
[7195]1## $Id: department.py 10226 2013-05-24 17:54:10Z 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
[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 = [
[10226]41        'waeup.local.ApplicationsManager',
[8993]42        'waeup.local.DepartmentManager',
43        'waeup.local.ClearanceOfficer',
44        'waeup.local.UGClearanceOfficer',
45        'waeup.local.PGClearanceOfficer',
46        'waeup.local.CourseAdviser100',
47        'waeup.local.CourseAdviser200',
48        'waeup.local.CourseAdviser300',
49        'waeup.local.CourseAdviser400',
50        'waeup.local.CourseAdviser500',
51        'waeup.local.CourseAdviser600',
[10064]52        'waeup.local.CourseAdviser700',
53        'waeup.local.CourseAdviser800',
[8993]54        ]
[6152]55
[4789]56    def __init__(self,
57                 title=u'Unnamed Department',
58                 title_prefix=u'department',
59                 code=u"NA", **kw):
60        super(Department, self).__init__(**kw)
61        self.title = title
62        self.title_prefix = title_prefix
63        self.code = code
[7681]64        self.courses = CoursesContainer()
[4789]65        self.courses.__parent__ = self
66        self.courses.__name__ = 'courses'
[7681]67        self.certificates = CertificatesContainer()
[4789]68        self.certificates.__parent__ = self
69        self.certificates.__name__ = 'certificates'
70
71    def traverse(self, name):
72        """Deliver appropriate containers, if someone wants to go to courses
73        or departments.
74        """
75        if name == 'courses':
76            return self.courses
77        elif name == 'certificates':
78            return self.certificates
[9734]79        elif name == 'exports':
80            # create a virtual exports container and return it
[9797]81            container = VirtualDepartmentExportJobContainer()
[9734]82            zope.location.location.located(container, self, 'exports')
83            return container
[4789]84        return None
[6813]85
[5988]86    def longtitle(self):
[7841]87        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
[6813]88        return "%s %s (%s)" % (
[7681]89            insttypes_dict[self.title_prefix],
[6813]90            self.title, self.code)
[4789]91
92class DepartmentFactory(grok.GlobalUtility):
93    """A factory for department containers.
94    """
95    grok.implements(IFactory)
96    grok.name(u'waeup.Department')
97    title = u"Create a new department.",
98    description = u"This factory instantiates new department instances."
99
100    def __call__(self, *args, **kw):
101        return Department(*args, **kw)
102
103    def getInterfaces(self):
104        """Get interfaces of objects provided by this factory.
105        """
106        return implementedBy(Department)
Note: See TracBrowser for help on using the repository browser.