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

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

Uses sources instead of vocabularies and feed sources with dictionaries defined in SIRPUtils. This way we can easily customize the sources.

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