source: main/waeup.sirp/trunk/src/waeup/sirp/university/department.py @ 7445

Last change on this file since 7445 was 7334, checked in by Henrik Bettermann, 13 years ago

Implement local CourseAdviser? roles. These roles can be assigned in departments and certificates. There are 6 different roles, one for each study level. getRolesForPrincipal grants the additional waeup.StudentsCourseAdviser? role only if the current level of a student corresponds with the level number in the external role name.

To do: Assign local roles on CertificateManageFormPage?. Add browser tests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1## $Id: department.py 7334 2011-12-12 14:11:21Z 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
21from zope.component import createObject
22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
24from waeup.sirp.university.interfaces import IDepartment, IDepartmentAdd
25from waeup.sirp.university.vocabularies import inst_types
26
27class Department(grok.Container):
28    """A university department.
29    """
30    grok.implements(IDepartment, IDepartmentAdd)
31
32    @property       # Make this method read_only and looking like an attr.
33    def local_roles(cls):
34        return ['waeup.local.DepartmentManager',
35                'waeup.local.ClearanceOfficer',
36                'waeup.local.CourseAdviser100',
37                'waeup.local.CourseAdviser200',
38                'waeup.local.CourseAdviser300',
39                'waeup.local.CourseAdviser400',
40                'waeup.local.CourseAdviser500',
41                'waeup.local.CourseAdviser600',
42                ]
43
44    # A simple counter for ids.
45    next_id = 0L
46
47    def __init__(self,
48                 title=u'Unnamed Department',
49                 title_prefix=u'department',
50                 code=u"NA", **kw):
51        super(Department, self).__init__(**kw)
52        self.title = title
53        self.title_prefix = title_prefix
54        self.code = code
55        self.courses = createObject(u'waeup.CoursesContainer')
56        self.courses.__parent__ = self
57        self.courses.__name__ = 'courses'
58        self.certificates = createObject(u'waeup.CertificatesContainer')
59        self.certificates.__parent__ = self
60        self.certificates.__name__ = 'certificates'
61
62    def traverse(self, name):
63        """Deliver appropriate containers, if someone wants to go to courses
64        or departments.
65        """
66        if name == 'courses':
67            return self.courses
68        elif name == 'certificates':
69            return self.certificates
70        return None
71
72    def longtitle(self):
73        return "%s %s (%s)" % (
74            inst_types.getTerm(self.title_prefix).title,
75            self.title, self.code)
76
77
78class DepartmentFactory(grok.GlobalUtility):
79    """A factory for department containers.
80    """
81    grok.implements(IFactory)
82    grok.name(u'waeup.Department')
83    title = u"Create a new department.",
84    description = u"This factory instantiates new department instances."
85
86    def __call__(self, *args, **kw):
87        return Department(*args, **kw)
88
89    def getInterfaces(self):
90        """Get interfaces of objects provided by this factory.
91        """
92        return implementedBy(Department)
Note: See TracBrowser for help on using the repository browser.