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 |
---|
8 | |
---|
9 | class Department(grok.Container): |
---|
10 | """A university department. |
---|
11 | """ |
---|
12 | grok.implements(IDepartment) |
---|
13 | |
---|
14 | # A simple counter for ids. |
---|
15 | next_id = 0L |
---|
16 | |
---|
17 | def __init__(self, |
---|
18 | title=u'Unnamed Department', |
---|
19 | title_prefix=u'department', |
---|
20 | code=u"NA", **kw): |
---|
21 | super(Department, self).__init__(**kw) |
---|
22 | self.title = title |
---|
23 | self.title_prefix = title_prefix |
---|
24 | self.code = code |
---|
25 | self.courses = createObject(u'waeup.CourseContainer') |
---|
26 | self.courses.__parent__ = self |
---|
27 | self.courses.__name__ = 'courses' |
---|
28 | self.certificates = createObject(u'waeup.CertificateContainer') |
---|
29 | self.certificates.__parent__ = self |
---|
30 | self.certificates.__name__ = 'certificates' |
---|
31 | |
---|
32 | def traverse(self, name): |
---|
33 | """Deliver appropriate containers, if someone wants to go to courses |
---|
34 | or departments. |
---|
35 | """ |
---|
36 | if name == 'courses': |
---|
37 | return self.courses |
---|
38 | elif name == 'certificates': |
---|
39 | return self.certificates |
---|
40 | return None |
---|
41 | |
---|
42 | |
---|
43 | class DepartmentFactory(grok.GlobalUtility): |
---|
44 | """A factory for department containers. |
---|
45 | """ |
---|
46 | grok.implements(IFactory) |
---|
47 | grok.name(u'waeup.Department') |
---|
48 | title = u"Create a new department.", |
---|
49 | description = u"This factory instantiates new department instances." |
---|
50 | |
---|
51 | def __call__(self, *args, **kw): |
---|
52 | return Department(*args, **kw) |
---|
53 | |
---|
54 | def getInterfaces(self): |
---|
55 | """Get interfaces of objects provided by this factory. |
---|
56 | """ |
---|
57 | return implementedBy(Department) |
---|