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

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

Revert r6151. The ContainerManageFormPage? does not make sense. Its code cannot be reused.

Implement local role assignment on DepartmentManageFormPage?.

There is a lot of recurring code in pages.py. I have no ideas how to reuse the code.

  • 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            {'name':'waeup.local.DepartmentOfficer',
19             'title':'Department Officer'},
20            ]
21
22    # A simple counter for ids.
23    next_id = 0L
24
25    def __init__(self,
26                 title=u'Unnamed Department',
27                 title_prefix=u'department',
28                 code=u"NA", **kw):
29        super(Department, self).__init__(**kw)
30        self.title = title
31        self.title_prefix = title_prefix
32        self.code = code
33        self.courses = createObject(u'waeup.CourseContainer')
34        self.courses.__parent__ = self
35        self.courses.__name__ = 'courses'
36        self.certificates = createObject(u'waeup.CertificateContainer')
37        self.certificates.__parent__ = self
38        self.certificates.__name__ = 'certificates'
39
40    def traverse(self, name):
41        """Deliver appropriate containers, if someone wants to go to courses
42        or departments.
43        """
44        if name == 'courses':
45            return self.courses
46        elif name == 'certificates':
47            return self.certificates
48        return None
49       
50    def longtitle(self):
51        return "%s %s (%s)" % (inst_types.getTerm(self.title_prefix).title,
52                                                  self.title,
53                                                  self.code)
54       
55
56class DepartmentFactory(grok.GlobalUtility):
57    """A factory for department containers.
58    """
59    grok.implements(IFactory)
60    grok.name(u'waeup.Department')
61    title = u"Create a new department.",
62    description = u"This factory instantiates new department instances."
63
64    def __call__(self, *args, **kw):
65        return Department(*args, **kw)
66
67    def getInterfaces(self):
68        """Get interfaces of objects provided by this factory.
69        """
70        return implementedBy(Department)
Note: See TracBrowser for help on using the repository browser.