source: main/waeup.kofa/trunk/src/waeup/kofa/doctests/app.txt @ 14935

Last change on this file since 14935 was 14511, checked in by Henrik Bettermann, 8 years ago

Add officer name fields do IDepartment and IFaculty. Plugins must be updated!

File size: 3.0 KB
Line 
1Central Components
2******************
3
4.. :doctest:
5.. :layer: waeup.kofa.testing.KofaUnitTestLayer
6
7.. module:: waeup.kofa.app
8
9
10Creating `University` instances
11===============================
12
13As :class:`University` instances make use of the Zope Component
14Architecture (ZCA), we have to setup the basic component registries,
15before we can create instances. We do this by simply grokking the
16whole :mod:`waeup` package. This way all interfaces, utilities and adapters
17defined in the package are looked up and registered with the global
18registries (this is done by the testlayer automatically).
19
20Now we can import the :class:`University` class and create an
21instance:
22
23  >>> from waeup.kofa.app import University
24  >>> myuniversity = University()
25  >>> myuniversity
26  <waeup.kofa.app.University object at 0x...>
27
28Instances of `University` comply with the interface
29`waeup.kofa.interfaces.IUniversity`:
30
31  >>> from zope.interface.verify import verifyClass
32  >>> from waeup.kofa.interfaces import IUniversity
33  >>> verifyClass(IUniversity, University)
34  True
35
36A freshly created instance provides the attributes promised by the
37interface:
38
39  >>> from waeup.kofa.app import University
40  >>> myuniversity = University()
41  >>> myuniversity['configuration'].name
42  u'Sample University'
43
44  >>> myuniversity['faculties']
45  <waeup.kofa.university.facultiescontainer.FacultiesContainer object at 0x...>
46
47  >>> myuniversity['students']
48  <waeup.kofa.students.container.StudentsContainer object at 0x...>
49
50  >>> myuniversity['users']
51  <waeup.kofa.userscontainer.UsersContainer object at 0x...>
52
53  >>> myuniversity['datacenter']
54  <waeup.kofa.datacenter.DataCenter object at 0x...>
55
56  >>> myuniversity['configuration']
57  <waeup.kofa.configuration.ConfigurationContainer object at 0x...>
58
59Kofa plugins
60============
61
62waeup.kofa provides an API to 'plugin' components. Things that should
63be setup at creation time of a Kofa application can indicate
64that by providing a utility providing IKofaPlugin.
65
66The plugins are looked up by an created app, which then will call the
67``setup()`` method of each plugin.
68
69   >>> from waeup.kofa.interfaces import IKofaPluggable
70   >>> from zope.component import getAdapters, getUtilitiesFor
71   >>> sorted(list(getUtilitiesFor(IKofaPluggable)))
72   [(u'academics', <waeup.kofa.university.facultiescontainer.AcademicsPlugin ...)]
73
74
75We can provide a new plugin like this:
76
77   >>> import grok
78   >>> from waeup.kofa.interfaces import IKofaPluggable
79   >>> class MyPlugin(grok.GlobalUtility):
80   ...   grok.implements(IKofaPluggable)
81   ...   def setup(self, site, name, logger):
82   ...     print "Setup was called for"
83   ...     print site
84   ...   def update(self, site, name, logger):
85   ...     pass
86
87When we register the plugin
88
89   >>> grok.testing.grok_component('MyPlugin', MyPlugin)
90   True
91
92and setup a new Kofa instance, we will get a message:
93
94   >>> from waeup.kofa.app import University
95   >>> site = University()
96   Setup was called for
97   <waeup.kofa.app.University object at 0x...>
98
99Apparently the plugin can do with the University object whatever it
100likes. That's what plugins are for.
Note: See TracBrowser for help on using the repository browser.