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

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

Change class attribute from list of dicts to dict. This makes configuration less error-prone.

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