source: main/waeup.sirp/trunk/src/waeup/sirp/university/department.py @ 6114

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

Implement title_prefix vocabulary. Remove redundant getName method and replace by the longtitle property.

  • Property svn:eol-style set to native
File size: 2.1 KB
RevLine 
[4789]1"""University departments.
2"""
3import grok
4from zope.component import createObject
5from zope.component.interfaces import IFactory
6from zope.interface import implementedBy
[5953]7from waeup.sirp.university.interfaces import IDepartment, IDepartmentAdd
[5988]8from waeup.sirp.university.vocabularies import inst_types
[4789]9
10class Department(grok.Container):
11    """A university department.
12    """
[5953]13    grok.implements(IDepartment, IDepartmentAdd)
[4789]14
15    # A simple counter for ids.
16    next_id = 0L
17   
18    def __init__(self,
19                 title=u'Unnamed Department',
20                 title_prefix=u'department',
21                 code=u"NA", **kw):
22        super(Department, self).__init__(**kw)
23        self.title = title
24        self.title_prefix = title_prefix
25        self.code = code
26        self.courses = createObject(u'waeup.CourseContainer')
27        self.courses.__parent__ = self
28        self.courses.__name__ = 'courses'
29        self.certificates = createObject(u'waeup.CertificateContainer')
30        self.certificates.__parent__ = self
31        self.certificates.__name__ = 'certificates'
32
33    def traverse(self, name):
34        """Deliver appropriate containers, if someone wants to go to courses
35        or departments.
36        """
37        if name == 'courses':
38            return self.courses
39        elif name == 'certificates':
40            return self.certificates
41        return None
42       
[5988]43    def longtitle(self):
44        return "%s %s (%s)" % (inst_types.getTerm(self.title_prefix).title,
45                                                  self.title,
46                                                  self.code)
47       
[4789]48
49class DepartmentFactory(grok.GlobalUtility):
50    """A factory for department containers.
51    """
52    grok.implements(IFactory)
53    grok.name(u'waeup.Department')
54    title = u"Create a new department.",
55    description = u"This factory instantiates new department instances."
56
57    def __call__(self, *args, **kw):
58        return Department(*args, **kw)
59
60    def getInterfaces(self):
61        """Get interfaces of objects provided by this factory.
62        """
63        return implementedBy(Department)
Note: See TracBrowser for help on using the repository browser.