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 | # 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 | |
---|
43 | def longtitle(self): |
---|
44 | return "%s %s (%s)" % (inst_types.getTerm(self.title_prefix).title, |
---|
45 | self.title, |
---|
46 | self.code) |
---|
47 | |
---|
48 | |
---|
49 | class 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) |
---|