1 | """University departments. |
---|
2 | """ |
---|
3 | import grok |
---|
4 | from zope.component import createObject |
---|
5 | from zope.component.interfaces import IFactory |
---|
6 | from zope.interface import implementedBy |
---|
7 | from waeup.sirp.university.interfaces import IDepartment, IDepartmentAdd |
---|
8 | from waeup.sirp.university.vocabularies import inst_types |
---|
9 | |
---|
10 | class 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 ['waeup.local.DepartmentManager', |
---|
18 | 'waeup.local.ClearanceOfficer',] |
---|
19 | |
---|
20 | # A simple counter for ids. |
---|
21 | next_id = 0L |
---|
22 | |
---|
23 | def __init__(self, |
---|
24 | title=u'Unnamed Department', |
---|
25 | title_prefix=u'department', |
---|
26 | code=u"NA", **kw): |
---|
27 | super(Department, self).__init__(**kw) |
---|
28 | self.title = title |
---|
29 | self.title_prefix = title_prefix |
---|
30 | self.code = code |
---|
31 | self.courses = createObject(u'waeup.CourseContainer') |
---|
32 | self.courses.__parent__ = self |
---|
33 | self.courses.__name__ = 'courses' |
---|
34 | self.certificates = createObject(u'waeup.CertificateContainer') |
---|
35 | self.certificates.__parent__ = self |
---|
36 | self.certificates.__name__ = 'certificates' |
---|
37 | |
---|
38 | def traverse(self, name): |
---|
39 | """Deliver appropriate containers, if someone wants to go to courses |
---|
40 | or departments. |
---|
41 | """ |
---|
42 | if name == 'courses': |
---|
43 | return self.courses |
---|
44 | elif name == 'certificates': |
---|
45 | return self.certificates |
---|
46 | return None |
---|
47 | |
---|
48 | def longtitle(self): |
---|
49 | return "%s %s (%s)" % ( |
---|
50 | inst_types.getTerm(self.title_prefix).title, |
---|
51 | self.title, self.code) |
---|
52 | |
---|
53 | |
---|
54 | class DepartmentFactory(grok.GlobalUtility): |
---|
55 | """A factory for department containers. |
---|
56 | """ |
---|
57 | grok.implements(IFactory) |
---|
58 | grok.name(u'waeup.Department') |
---|
59 | title = u"Create a new department.", |
---|
60 | description = u"This factory instantiates new department instances." |
---|
61 | |
---|
62 | def __call__(self, *args, **kw): |
---|
63 | return Department(*args, **kw) |
---|
64 | |
---|
65 | def getInterfaces(self): |
---|
66 | """Get interfaces of objects provided by this factory. |
---|
67 | """ |
---|
68 | return implementedBy(Department) |
---|