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

Last change on this file since 6160 was 6160, checked in by Henrik Bettermann, 13 years ago

Change class attribute from list of dicts to dict. This makes configuration less error-prone.

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