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
RevLine 
[4789]1"""Faculty components.
2"""
3
[3526]4import grok
[4789]5from zope.component.interfaces import IFactory
6from zope.interface import implementedBy
[5953]7from waeup.sirp.university.interfaces import (
8    IFaculty, IFacultyAdd, IDepartment)
[6145]9from waeup.sirp.university.vocabularies import inst_types
[3526]10
[4789]11class Faculty(grok.Container):
12    """A university faculty.
13    """
[5953]14    grok.implements(IFaculty, IFacultyAdd)
[3526]15
[6145]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
[4789]23    def __init__(self,
24                 title=u'Unnamed Faculty',
25                 title_prefix=u'faculty',
26                 code=u'NA', **kw):
[3526]27        super(Faculty, self).__init__(**kw)
[4789]28        self.title = title
29        self.title_prefix = title_prefix
30        self.code = code
[3526]31
[4789]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
[3526]38
[4789]39    def clear(self):
40        """Remove all departments from faculty.
41        """
42        keys = self.keys()
43        for key in keys:
44            del self[key]
[3526]45
[5988]46    def longtitle(self):
[5994]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
[6145]55
[4789]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.