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

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

Be prepared, if a faculty does not has a valid title_prefix.

  • Property svn:eol-style set to native
File size: 1.8 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        try:
41            result = "%s %s (%s)" % (
42                inst_types.getTerm(
43                    self.title_prefix).title,
44                self.title, self.code)
45        except:
46            result = "%s (%s)" % (self.title, self.code)
47        return result
48       
49class FacultyFactory(grok.GlobalUtility):
50    """A factory for faculty containers.
51    """
52    grok.implements(IFactory)
53    grok.name(u'waeup.Faculty')
54    title = u"Create a new faculty.",
55    description = u"This factory instantiates new faculty instances."
56
57    def __call__(self, *args, **kw):
58        return Faculty()
59
60    def getInterfaces(self):
61        return implementedBy(Faculty)
Note: See TracBrowser for help on using the repository browser.