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 [ |
---|
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 | |
---|
56 | class 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) |
---|