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

Last change on this file since 10226 was 10226, checked in by Henrik Bettermann, 11 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
Line 
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##
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.ApplicationsManager',
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',
52        'waeup.local.CourseAdviser700',
53        'waeup.local.CourseAdviser800',
54        ]
55
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
64        self.courses = CoursesContainer()
65        self.courses.__parent__ = self
66        self.courses.__name__ = 'courses'
67        self.certificates = CertificatesContainer()
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
79        elif name == 'exports':
80            # create a virtual exports container and return it
81            container = VirtualDepartmentExportJobContainer()
82            zope.location.location.located(container, self, 'exports')
83            return container
84        return None
85
86    def longtitle(self):
87        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
88        return "%s %s (%s)" % (
89            insttypes_dict[self.title_prefix],
90            self.title, self.code)
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.