source: main/waeup.sirp/trunk/src/waeup/sirp/app.txt @ 6906

Last change on this file since 6906 was 6897, checked in by Henrik Bettermann, 13 years ago

Merge README.txt and app.txt. This will also catch the error on Issoufou's system.

File size: 4.3 KB
Line 
1:mod:`waeup.sirp.app` -- central components for a WAeUP portal
2**************************************************************
3
4.. :doctest:
5.. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer
6
7.. module:: waeup.sirp.app
8
9.. class:: University
10
11  The main WAeUP application object is given with
12  :class:`University`. It provides the main containers as faculties,
13  hostels, etc.
14
15  .. attribute:: name
16
17     A string. The name of a university.
18
19  .. attribute:: faculties
20
21     An arbitrary object containing "faculties". In the case of
22     `University` it is a container of type
23     `waeup.sirp.interfaces.IFacultyContainer`.
24
25
26Creating `University` instances
27===============================
28
29As :class:`University` instances make use of the Zope Component
30Architecture (ZCA), we have to setup the basic component registries,
31before we can create instances. We do this by simply grokking the
32whole :mod:`waeup` package. This way all interfaces, utilities and adapters
33defined in the package are looked up and registered with the global
34registries (this is done by the testlayer automatically).
35
36Now we can import the :class:`University` class and create an
37instance:
38
39    >>> from waeup.sirp.app import University
40    >>> myuniversity = University()
41    >>> myuniversity
42    <waeup.sirp.app.University object at 0x...>
43
44Instances of `University` comply with the interface
45`waeup.sirp.interfaces.IUniversity`:
46
47    >>> from zope.interface.verify import verifyClass
48    >>> from waeup.sirp.interfaces import IUniversity
49    >>> verifyClass(IUniversity, University)
50    True
51
52A freshly created instance provides the attributes promised by the
53interface:
54
55    >>> from waeup.sirp.app import University
56    >>> myuniversity = University()
57    >>> myuniversity.name
58    u'Sample University'
59
60    >>> myuniversity['faculties']
61    <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...>
62
63  >>> myuniversity['students']
64  <waeup.sirp.students.container.StudentsContainer object at 0x...>
65
66  >>> myuniversity['users']
67  <waeup.sirp.users.UserContainer object at 0x...>
68
69  >>> myuniversity['datacenter']
70  <waeup.sirp.datacenter.DataCenter object at 0x...>
71
72We can export universities. For this we lookup an appropriate exporter
73first::
74
75  >>> from waeup.sirp.interfaces import IWAeUPExporter
76  >>> exporter = IWAeUPExporter(myuniversity)
77  >>> exporter
78  <waeup.sirp.utils.importexport.Exporter object at 0x...>
79
80Now we can trigger the export::
81
82  >>> exporter.export()
83  <cStringIO.StringO object at 0x...>
84
85We can also get an XML representation as file. If we do not provide a
86filepath, we will get an instance of `cStringIO.StringIO`, i.e. a
87memory file::
88
89  >>> from waeup.sirp.interfaces import IWAeUPXMLExporter
90  >>> exporter = IWAeUPXMLExporter(myuniversity)
91  >>> f = exporter.export()
92  >>> f
93  <cStringIO.StringO object at 0x...>
94
95  >>> print f.read()
96  <?xml version="1.0" encoding="utf-8" ?>
97  <pickle>
98    <initialized_object id="...">
99  ...
100  </pickle>
101
102WAeUP SIRP plugins
103==================
104
105waeup.sirp provides an API to 'plugin' components. Things that should
106be setup at creation time of a WAeUP SIRP application can indicate
107that by providing a utility providing IWAeUPSIRPPlugin.
108
109The plugins are looked up by an created app, which then will call the
110``setup()`` method of each plugin.
111
112   >>> from waeup.sirp.interfaces import IWAeUPSIRPPluggable
113   >>> from zope.component import getAdapters, getUtilitiesFor
114   >>> sorted(list(getUtilitiesFor(IWAeUPSIRPPluggable)))
115   [(u'accesscodes', <waeup.sirp.accesscodes...AccessCodePlugin ...)]
116
117
118We can provide a new plugin like this:
119
120   >>> import grok
121   >>> from waeup.sirp.interfaces import IWAeUPSIRPPluggable
122   >>> class MyPlugin(grok.GlobalUtility):
123   ...   grok.implements(IWAeUPSIRPPluggable)
124   ...   def setup(self, site, name, logger):
125   ...     print "Setup was called for"
126   ...     print site
127   ...   def update(self, site, name, logger):
128   ...     pass
129
130When we register the plugin
131
132   >>> grok.testing.grok_component('MyPlugin', MyPlugin)
133   True
134
135and setup a new WAeUP SIRP instance, we will get a message:
136
137   >>> from waeup.sirp.app import University
138   >>> site = University()
139   Setup was called for
140   <waeup.sirp.app.University object at 0x...>
141
142Apparently the plugin can do with the University object whatever it
143likes. That's what plugins are for.
Note: See TracBrowser for help on using the repository browser.