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

Last change on this file since 6038 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
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):
[5994]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
[4789]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.