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

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

Let models implement also the appropriate I...Add interfaces.

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