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

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

Use only getName method from helpers.py. Don't define getName for each container class.

  • 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 IFaculty, IDepartment
8
9class Faculty(grok.Container):
10    """A university faculty.
11    """
12    grok.implements(IFaculty)
13
14    def __init__(self,
15                 title=u'Unnamed Faculty',
16                 title_prefix=u'faculty',
17                 code=u'NA', **kw):
18        super(Faculty, self).__init__(**kw)
19        self.title = title
20        self.title_prefix = title_prefix
21        self.code = code
22
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
29
30    def clear(self):
31        """Remove all departments from faculty.
32        """
33        keys = self.keys()
34        for key in keys:
35            del self[key]
36
37    #def getName(self, key):
38    #    """Get complete department 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.