[11949] | 1 | :mod:`waeup.ikoba.app` -- central components for Ikoba |
---|
[7321] | 2 | **************************************************** |
---|
[3933] | 3 | |
---|
[5140] | 4 | .. :doctest: |
---|
[11949] | 5 | .. :layer: waeup.ikoba.testing.IkobaUnitTestLayer |
---|
[3933] | 6 | |
---|
[11949] | 7 | .. module:: waeup.ikoba.app |
---|
[3933] | 8 | |
---|
[11952] | 9 | .. class:: Institution |
---|
[4273] | 10 | |
---|
[11949] | 11 | The main Ikoba application object is given with |
---|
[11952] | 12 | :class:`Institution`. It provides the main containers as faculties, |
---|
[4273] | 13 | hostels, etc. |
---|
| 14 | |
---|
| 15 | .. attribute:: name |
---|
| 16 | |
---|
[11952] | 17 | A string. The name of a institution. |
---|
[4273] | 18 | |
---|
| 19 | .. attribute:: faculties |
---|
| 20 | |
---|
| 21 | An arbitrary object containing "faculties". In the case of |
---|
[11952] | 22 | `Institution` it is a container of type |
---|
[11949] | 23 | `waeup.ikoba.interfaces.IFacultiesContainer`. |
---|
[4273] | 24 | |
---|
| 25 | |
---|
[11952] | 26 | Creating `Institution` instances |
---|
[3933] | 27 | =============================== |
---|
| 28 | |
---|
[11952] | 29 | As :class:`Institution` instances make use of the Zope Component |
---|
[4273] | 30 | Architecture (ZCA), we have to setup the basic component registries, |
---|
| 31 | before we can create instances. We do this by simply grokking the |
---|
| 32 | whole :mod:`waeup` package. This way all interfaces, utilities and adapters |
---|
| 33 | defined in the package are looked up and registered with the global |
---|
[5140] | 34 | registries (this is done by the testlayer automatically). |
---|
[3933] | 35 | |
---|
[11952] | 36 | Now we can import the :class:`Institution` class and create an |
---|
[4273] | 37 | instance: |
---|
[3933] | 38 | |
---|
[11952] | 39 | >>> from waeup.ikoba.app import Institution |
---|
| 40 | >>> myinstitution = Institution() |
---|
| 41 | >>> myinstitution |
---|
| 42 | <waeup.ikoba.app.Institution object at 0x...> |
---|
[3933] | 43 | |
---|
[11952] | 44 | Instances of `Institution` comply with the interface |
---|
| 45 | `waeup.ikoba.interfaces.IInstitution`: |
---|
[3933] | 46 | |
---|
| 47 | >>> from zope.interface.verify import verifyClass |
---|
[11952] | 48 | >>> from waeup.ikoba.interfaces import IInstitution |
---|
| 49 | >>> verifyClass(IInstitution, Institution) |
---|
[3933] | 50 | True |
---|
| 51 | |
---|
[4273] | 52 | A freshly created instance provides the attributes promised by the |
---|
| 53 | interface: |
---|
[3933] | 54 | |
---|
[11952] | 55 | >>> from waeup.ikoba.app import Institution |
---|
| 56 | >>> myinstitution = Institution() |
---|
| 57 | >>> myinstitution['configuration'].name |
---|
| 58 | u'Sample Institution' |
---|
[3933] | 59 | |
---|
[11952] | 60 | >>> myinstitution['users'] |
---|
[11949] | 61 | <waeup.ikoba.userscontainer.UsersContainer object at 0x...> |
---|
[6897] | 62 | |
---|
[11952] | 63 | >>> myinstitution['datacenter'] |
---|
[11949] | 64 | <waeup.ikoba.datacenter.DataCenter object at 0x...> |
---|
[6897] | 65 | |
---|
[11952] | 66 | >>> myinstitution['configuration'] |
---|
[11949] | 67 | <waeup.ikoba.configuration.ConfigurationContainer object at 0x...> |
---|
[6907] | 68 | |
---|
[6897] | 69 | |
---|
[11949] | 70 | Ikoba plugins |
---|
[7321] | 71 | ============ |
---|
[6897] | 72 | |
---|
[11949] | 73 | waeup.ikoba provides an API to 'plugin' components. Things that should |
---|
| 74 | be setup at creation time of a Ikoba application can indicate |
---|
| 75 | that by providing a utility providing IIkobaPlugin. |
---|
[6897] | 76 | |
---|
| 77 | The plugins are looked up by an created app, which then will call the |
---|
| 78 | ``setup()`` method of each plugin. |
---|
| 79 | |
---|
[11949] | 80 | >>> from waeup.ikoba.interfaces import IIkobaPluggable |
---|
[6897] | 81 | >>> from zope.component import getAdapters, getUtilitiesFor |
---|
[11949] | 82 | >>> sorted(list(getUtilitiesFor(IIkobaPluggable))) |
---|
| 83 | [(u'mandates', <waeup.ikoba.mandates.container.MandatesPlugin ...)] |
---|
[6897] | 84 | |
---|
| 85 | |
---|
| 86 | We can provide a new plugin like this: |
---|
| 87 | |
---|
| 88 | >>> import grok |
---|
[11949] | 89 | >>> from waeup.ikoba.interfaces import IIkobaPluggable |
---|
[6897] | 90 | >>> class MyPlugin(grok.GlobalUtility): |
---|
[11949] | 91 | ... grok.implements(IIkobaPluggable) |
---|
[6897] | 92 | ... def setup(self, site, name, logger): |
---|
| 93 | ... print "Setup was called for" |
---|
| 94 | ... print site |
---|
| 95 | ... def update(self, site, name, logger): |
---|
| 96 | ... pass |
---|
| 97 | |
---|
| 98 | When we register the plugin |
---|
| 99 | |
---|
| 100 | >>> grok.testing.grok_component('MyPlugin', MyPlugin) |
---|
| 101 | True |
---|
| 102 | |
---|
[11949] | 103 | and setup a new Ikoba instance, we will get a message: |
---|
[6897] | 104 | |
---|
[11952] | 105 | >>> from waeup.ikoba.app import Institution |
---|
| 106 | >>> site = Institution() |
---|
[6897] | 107 | Setup was called for |
---|
[11952] | 108 | <waeup.ikoba.app.Institution object at 0x...> |
---|
[6897] | 109 | |
---|
[11952] | 110 | Apparently the plugin can do with the Institution object whatever it |
---|
[7811] | 111 | likes. That's what plugins are for. |
---|