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

Last change on this file since 5273 was 5005, checked in by uli, 15 years ago

Fix references to academics stuff interfaces. This is the first step to make academics stuff pluggable.

  • Property svn:eol-style set to native
File size: 1.6 KB
RevLine 
[4789]1"""Faculty components.
2"""
3
[3526]4import grok
[4789]5from zope.component.interfaces import IFactory
6from zope.interface import implementedBy
[5005]7from waeup.sirp.university.interfaces import IFaculty, IDepartment
[3526]8
[4789]9class Faculty(grok.Container):
10    """A university faculty.
11    """
[3526]12    grok.implements(IFaculty)
13
[4789]14    def __init__(self,
15                 title=u'Unnamed Faculty',
16                 title_prefix=u'faculty',
17                 code=u'NA', **kw):
[3526]18        super(Faculty, self).__init__(**kw)
[4789]19        self.title = title
20        self.title_prefix = title_prefix
21        self.code = code
[3526]22
[4789]23    def addDepartment(self, department):
24        """Add a department to the faculty.
25        """
26        if not IDepartment.providedBy(department):
27            raise TypeError('Faculties contain only IDepartment instances')
28        self[department.code] = department
[3526]29
[4789]30    def clear(self):
31        """Remove all departments from faculty.
32        """
33        keys = self.keys()
34        for key in keys:
35            del self[key]
[3526]36
[4789]37    def getName(self, key):
38        """Get complete faculty name.
39        """
40        if key in self.keys():
41            dept = self[key]
42            prefix = dept.title_prefix
43            prefix = prefix[0].upper() + prefix[1:]
44            return '%s of %s' % (prefix, dept.title)
45
46       
47class FacultyFactory(grok.GlobalUtility):
48    """A factory for faculty containers.
49    """
50    grok.implements(IFactory)
51    grok.name(u'waeup.Faculty')
52    title = u"Create a new faculty.",
53    description = u"This factory instantiates new faculty instances."
54
55    def __call__(self, *args, **kw):
56        return Faculty()
57
58    def getInterfaces(self):
59        return implementedBy(Faculty)
Note: See TracBrowser for help on using the repository browser.