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

Last change on this file since 13152 was 12960, checked in by Henrik Bettermann, 10 years ago

Remove deprecated xml importer and exporter components.

File size: 3.0 KB
RevLine 
[12951]1Central Components
2******************
[3933]3
[5140]4.. :doctest:
[7819]5.. :layer: waeup.kofa.testing.KofaUnitTestLayer
[3933]6
[7811]7.. module:: waeup.kofa.app
[3933]8
[4273]9
[3933]10Creating `University` instances
11===============================
12
[4273]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
[5140]18registries (this is done by the testlayer automatically).
[3933]19
[4273]20Now we can import the :class:`University` class and create an
21instance:
[3933]22
[12951]23  >>> from waeup.kofa.app import University
24  >>> myuniversity = University()
25  >>> myuniversity
26  <waeup.kofa.app.University object at 0x...>
[3933]27
28Instances of `University` comply with the interface
[7811]29`waeup.kofa.interfaces.IUniversity`:
[3933]30
[12951]31  >>> from zope.interface.verify import verifyClass
32  >>> from waeup.kofa.interfaces import IUniversity
33  >>> verifyClass(IUniversity, University)
34  True
[3933]35
[4273]36A freshly created instance provides the attributes promised by the
37interface:
[3933]38
[12951]39  >>> from waeup.kofa.app import University
40  >>> myuniversity = University()
41  >>> myuniversity['configuration'].name
42  u'Sample University'
[3933]43
[12951]44  >>> myuniversity['faculties']
45  <waeup.kofa.university.facultiescontainer.FacultiesContainer object at 0x...>
[6897]46
47  >>> myuniversity['students']
[7811]48  <waeup.kofa.students.container.StudentsContainer object at 0x...>
[6897]49
50  >>> myuniversity['users']
[7811]51  <waeup.kofa.userscontainer.UsersContainer object at 0x...>
[6897]52
53  >>> myuniversity['datacenter']
[7811]54  <waeup.kofa.datacenter.DataCenter object at 0x...>
[6897]55
[6907]56  >>> myuniversity['configuration']
[7811]57  <waeup.kofa.configuration.ConfigurationContainer object at 0x...>
[6907]58
[7819]59Kofa plugins
[7321]60============
[6897]61
[7811]62waeup.kofa provides an API to 'plugin' components. Things that should
[7819]63be setup at creation time of a Kofa application can indicate
64that by providing a utility providing IKofaPlugin.
[6897]65
66The plugins are looked up by an created app, which then will call the
67``setup()`` method of each plugin.
68
[7819]69   >>> from waeup.kofa.interfaces import IKofaPluggable
[6897]70   >>> from zope.component import getAdapters, getUtilitiesFor
[7819]71   >>> sorted(list(getUtilitiesFor(IKofaPluggable)))
[7811]72   [(u'accesscodes', <waeup.kofa.accesscodes...AccessCodePlugin ...)]
[6897]73
74
75We can provide a new plugin like this:
76
77   >>> import grok
[7819]78   >>> from waeup.kofa.interfaces import IKofaPluggable
[6897]79   >>> class MyPlugin(grok.GlobalUtility):
[7819]80   ...   grok.implements(IKofaPluggable)
[6897]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
[7819]92and setup a new Kofa instance, we will get a message:
[6897]93
[7811]94   >>> from waeup.kofa.app import University
[6897]95   >>> site = University()
96   Setup was called for
[7811]97   <waeup.kofa.app.University object at 0x...>
[6897]98
99Apparently the plugin can do with the University object whatever it
[7811]100likes. That's what plugins are for.
Note: See TracBrowser for help on using the repository browser.