1 | import grok |
---|
2 | from zope.app.authentication.authentication import PluggableAuthentication |
---|
3 | from zope.app.security.interfaces import IAuthentication |
---|
4 | from zope.component import createObject |
---|
5 | |
---|
6 | from waeup.interfaces import IUniversity, ICSVDataReceivers |
---|
7 | from waeup.authentication import setup_authentication |
---|
8 | from waeup.datacenter import DataCenter |
---|
9 | from waeup.users import UserContainer |
---|
10 | |
---|
11 | class University(grok.Application, grok.Container): |
---|
12 | """A university. |
---|
13 | """ |
---|
14 | grok.implements(IUniversity, ICSVDataReceivers) |
---|
15 | # Setup authentication for this app. Note: this is only |
---|
16 | # initialized, when a new instance of this app is created. |
---|
17 | grok.local_utility( |
---|
18 | PluggableAuthentication, provides = IAuthentication, |
---|
19 | setup = setup_authentication) |
---|
20 | |
---|
21 | def __init__(self, name=u'Sample University', **kw): |
---|
22 | super(University, self).__init__(**kw) |
---|
23 | self.name = name |
---|
24 | self.setup() |
---|
25 | |
---|
26 | def setup(self): |
---|
27 | self.students = createObject(u'waeup.StudentContainer') |
---|
28 | self.hostels = createObject(u'waeup.HostelContainer') |
---|
29 | self.faculties = createObject(u'waeup.FacultyContainer') |
---|
30 | # TODO: We need this to get URLs of subobjects. Can we avoid it? |
---|
31 | self.faculties.__parent__ = self |
---|
32 | self.faculties.__name__ = 'faculties' |
---|
33 | self['users'] = UserContainer() |
---|
34 | self['datacenter'] = DataCenter() |
---|
35 | |
---|
36 | def traverse(self, name): |
---|
37 | # If someone requests a subobject 'faculties', we return our |
---|
38 | # `faculties` attribute. |
---|
39 | if name == 'faculties': |
---|
40 | return self.faculties |
---|
41 | elif name == 'hostels': |
---|
42 | return self.hostels |
---|
43 | elif name == 'students': |
---|
44 | return self.students |
---|
45 | elif name == 'users': |
---|
46 | return self['users'] |
---|
47 | elif name == 'datacenter': |
---|
48 | return self['datacenter'] |
---|
49 | return None |
---|