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

Last change on this file since 5993 was 5988, checked in by Henrik Bettermann, 14 years ago

Implement title_prefix vocabulary. Remove redundant getName method and replace by the longtitle property.

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