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

Last change on this file since 5990 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
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)
[5988]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
[4789]16    def __init__(self,
17                 title=u'Unnamed Faculty',
18                 title_prefix=u'faculty',
19                 code=u'NA', **kw):
[3526]20        super(Faculty, self).__init__(**kw)
[4789]21        self.title = title
22        self.title_prefix = title_prefix
23        self.code = code
[3526]24
[4789]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
[3526]31
[4789]32    def clear(self):
33        """Remove all departments from faculty.
34        """
35        keys = self.keys()
36        for key in keys:
37            del self[key]
[3526]38
[5988]39    def longtitle(self):
40        return "%s %s (%s)" % (inst_types.getTerm(self.title_prefix).title,
41                                                  self.title,
42                                                  self.code)
[4789]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.