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

Last change on this file since 6316 was 6162, checked in by uli, 14 years ago

Retrieve title from role, not from arbitrary dicts.

  • Property svn:eol-style set to native
File size: 1.9 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 ['waeup.local.DepartmentOfficer']
19
20    def __init__(self,
21                 title=u'Unnamed Faculty',
22                 title_prefix=u'faculty',
23                 code=u'NA', **kw):
24        super(Faculty, self).__init__(**kw)
25        self.title = title
26        self.title_prefix = title_prefix
27        self.code = code
28
29    def addDepartment(self, department):
30        """Add a department to the faculty.
31        """
32        if not IDepartment.providedBy(department):
33            raise TypeError('Faculties contain only IDepartment instances')
34        self[department.code] = department
35
36    def clear(self):
37        """Remove all departments from faculty.
38        """
39        keys = self.keys()
40        for key in keys:
41            del self[key]
42
43    def longtitle(self):
44        try:
45            result = "%s %s (%s)" % (
46                inst_types.getTerm(
47                    self.title_prefix).title,
48                self.title, self.code)
49        except:
50            result = "%s (%s)" % (self.title, self.code)
51        return result
52
53class FacultyFactory(grok.GlobalUtility):
54    """A factory for faculty containers.
55    """
56    grok.implements(IFactory)
57    grok.name(u'waeup.Faculty')
58    title = u"Create a new faculty.",
59    description = u"This factory instantiates new faculty instances."
60
61    def __call__(self, *args, **kw):
62        return Faculty()
63
64    def getInterfaces(self):
65        return implementedBy(Faculty)
Note: See TracBrowser for help on using the repository browser.