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

Last change on this file since 6152 was 6145, checked in by uli, 14 years ago

Make local_roles a property of Faculty.

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1"""Faculty components.
2"""
3
4import grok
5from zope.component.interfaces import IFactory
6from zope.interface import implementedBy
7from waeup.sirp.university.interfaces import (
8    IFaculty, IFacultyAdd, IDepartment)
9from waeup.sirp.university.vocabularies import inst_types
10
11class Faculty(grok.Container):
12    """A university faculty.
13    """
14    grok.implements(IFaculty, IFacultyAdd)
15
16    @property       # Make this method read_only and looking like an attr.
17    def local_roles(cls):
18        return [
19            {'name':'waeup.local.DepartmentOfficer',
20             'title':'Department Officer'},
21            ]
22
23    def __init__(self,
24                 title=u'Unnamed Faculty',
25                 title_prefix=u'faculty',
26                 code=u'NA', **kw):
27        super(Faculty, self).__init__(**kw)
28        self.title = title
29        self.title_prefix = title_prefix
30        self.code = code
31
32    def addDepartment(self, department):
33        """Add a department to the faculty.
34        """
35        if not IDepartment.providedBy(department):
36            raise TypeError('Faculties contain only IDepartment instances')
37        self[department.code] = department
38
39    def clear(self):
40        """Remove all departments from faculty.
41        """
42        keys = self.keys()
43        for key in keys:
44            del self[key]
45
46    def longtitle(self):
47        try:
48            result = "%s %s (%s)" % (
49                inst_types.getTerm(
50                    self.title_prefix).title,
51                self.title, self.code)
52        except:
53            result = "%s (%s)" % (self.title, self.code)
54        return result
55
56class FacultyFactory(grok.GlobalUtility):
57    """A factory for faculty containers.
58    """
59    grok.implements(IFactory)
60    grok.name(u'waeup.Faculty')
61    title = u"Create a new faculty.",
62    description = u"This factory instantiates new faculty instances."
63
64    def __call__(self, *args, **kw):
65        return Faculty()
66
67    def getInterfaces(self):
68        return implementedBy(Faculty)
Note: See TracBrowser for help on using the repository browser.