source: main/waeup.sirp/trunk/src/waeup/sirp/university/faculty.py @ 7727

Last change on this file since 7727 was 7724, checked in by uli, 13 years ago

If local_roles is used as a classmethod (and 'cls' instead of 'self'
seems to mean that), we should at least make this method a class
method. Maybe the use of @property is not the best here at all. On the
other hand longtitle is a typical candidate for @property and I wonder
why it is a regular method.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1## $Id: faculty.py 7724 2012-02-29 13:40:37Z 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##
18"""Faculty components.
19"""
20
21import grok
22from zope.component.interfaces import IFactory
23from zope.interface import implementedBy
24from zope.component import getUtility
25from waeup.sirp.interfaces import ISIRPUtils
26from waeup.sirp.university.interfaces import (
27    IFaculty, IFacultyAdd, IDepartment)
28
29class Faculty(grok.Container):
30    """A university faculty.
31    """
32    grok.implements(IFaculty, IFacultyAdd)
33
34    @property       # Make this method read_only and looking like an attr.
35    @classmethod
36    def local_roles(cls):
37        return ['waeup.local.DepartmentManager',
38                'waeup.local.ClearanceOfficer',
39                'waeup.local.CourseAdviser100',
40                'waeup.local.CourseAdviser200',
41                'waeup.local.CourseAdviser300',
42                'waeup.local.CourseAdviser400',
43                'waeup.local.CourseAdviser500',
44                'waeup.local.CourseAdviser600',
45                ]
46
47    def __init__(self,
48                 title=u'Unnamed Faculty',
49                 title_prefix=u'faculty',
50                 code=u'NA', **kw):
51        super(Faculty, self).__init__(**kw)
52        self.title = title
53        self.title_prefix = title_prefix
54        self.code = code
55
56    def addDepartment(self, department):
57        """Add a department to the faculty.
58        """
59        if not IDepartment.providedBy(department):
60            raise TypeError('Faculties contain only IDepartment instances')
61        self[department.code] = department
62
63    def longtitle(self):
64        insttypes_dict = getUtility(ISIRPUtils).getInstTypeDict()
65        result = "%s %s (%s)" % (
66            insttypes_dict[self.title_prefix],
67            self.title, self.code)
68        return result
69
70class FacultyFactory(grok.GlobalUtility):
71    """A factory for faculty containers.
72    """
73    grok.implements(IFactory)
74    grok.name(u'waeup.Faculty')
75    title = u"Create a new faculty.",
76    description = u"This factory instantiates new faculty instances."
77
78    def __call__(self, *args, **kw):
79        return Faculty()
80
81    def getInterfaces(self):
82        return implementedBy(Faculty)
Note: See TracBrowser for help on using the repository browser.