[4920] | 1 | The waeup.sirp package |
---|
| 2 | ********************** |
---|
[3521] | 3 | |
---|
| 4 | :Test-Layer: unit |
---|
| 5 | |
---|
| 6 | A portal software for student registration. |
---|
| 7 | |
---|
[4789] | 8 | Prerequisites |
---|
| 9 | ============= |
---|
| 10 | |
---|
| 11 | Before we can work with the environment, we have to register all the |
---|
| 12 | utilities, adapters, etc. We grok the `waeup` package to do that:: |
---|
| 13 | |
---|
| 14 | >>> import grok |
---|
[4920] | 15 | >>> grok.testing.grok('waeup.sirp') |
---|
[4789] | 16 | |
---|
[3521] | 17 | Universities |
---|
| 18 | ============ |
---|
| 19 | |
---|
| 20 | ``University`` objects are the base of all functionality provided by |
---|
| 21 | this package. They contain all facilities of a university. |
---|
| 22 | |
---|
| 23 | We can easily create universities:: |
---|
| 24 | |
---|
[4920] | 25 | >>> from waeup.sirp.app import University |
---|
[3521] | 26 | >>> u = University() |
---|
| 27 | >>> u |
---|
[4920] | 28 | <waeup.sirp.app.University object at 0x...> |
---|
[3521] | 29 | |
---|
| 30 | Universities have a name. |
---|
| 31 | |
---|
| 32 | >>> u.name |
---|
[4789] | 33 | u'Sample University' |
---|
[3521] | 34 | |
---|
[4789] | 35 | Universities are basically also containers for faculties, students and |
---|
| 36 | hostels:: |
---|
[3521] | 37 | |
---|
[4789] | 38 | >>> u['faculties'] |
---|
[4920] | 39 | <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...> |
---|
[4789] | 40 | |
---|
| 41 | >>> u['students'] |
---|
[4920] | 42 | <waeup.sirp.student.studentcontainer.StudentContainer object at 0x...> |
---|
[4789] | 43 | |
---|
| 44 | >>> u['hostels'] |
---|
[4920] | 45 | <waeup.sirp.hostel.hostelcontainer.HostelContainer object at 0x...> |
---|
[4789] | 46 | |
---|
| 47 | We can export universities. For this we lookup an appropriate exporter |
---|
| 48 | first:: |
---|
| 49 | |
---|
[4920] | 50 | >>> from waeup.sirp.interfaces import IWAeUPExporter |
---|
[4789] | 51 | >>> exporter = IWAeUPExporter(u) |
---|
| 52 | >>> exporter |
---|
[4920] | 53 | <waeup.sirp.utils.importexport.Exporter object at 0x...> |
---|
[4789] | 54 | |
---|
| 55 | Now we can trigger the export:: |
---|
| 56 | |
---|
| 57 | >>> exporter.export() |
---|
| 58 | <cStringIO.StringO object at 0x...> |
---|
| 59 | |
---|
| 60 | We can also get an XML representation as file. If we do not provide a |
---|
| 61 | filepath, we will get an instance of `cStringIO.StringIO`, i.e. a |
---|
| 62 | memory file:: |
---|
| 63 | |
---|
[4920] | 64 | >>> from waeup.sirp.interfaces import IWAeUPXMLExporter |
---|
[4789] | 65 | >>> exporter = IWAeUPXMLExporter(u) |
---|
| 66 | >>> f = exporter.export() |
---|
| 67 | >>> f |
---|
| 68 | <cStringIO.StringO object at 0x...> |
---|
| 69 | |
---|
| 70 | >>> print f.read() |
---|
| 71 | <?xml version="1.0" encoding="utf-8" ?> |
---|
| 72 | <pickle> |
---|
| 73 | <initialized_object id="..."> |
---|
| 74 | ... |
---|
| 75 | </pickle> |
---|
| 76 | |
---|
| 77 | |
---|
[3521] | 78 | Faculties |
---|
| 79 | ========= |
---|
| 80 | |
---|
| 81 | Faculties are containers for departments. They are intended to be |
---|
| 82 | managed by universities. |
---|
| 83 | |
---|
| 84 | We can create faculties easily:: |
---|
| 85 | |
---|
[4920] | 86 | >>> from waeup.sirp.university.faculty import Faculty |
---|
[3521] | 87 | >>> f = Faculty() |
---|
| 88 | >>> f |
---|
[4920] | 89 | <waeup.sirp.university.faculty.Faculty object at 0x...> |
---|
[3521] | 90 | |
---|
| 91 | Also faculties want to be named:: |
---|
| 92 | |
---|
[4789] | 93 | >>> f.title |
---|
[3521] | 94 | u'Unnamed Faculty' |
---|
| 95 | |
---|
| 96 | Departments |
---|
| 97 | =========== |
---|
| 98 | |
---|
[5072] | 99 | |
---|
| 100 | WAeUP SIRP plugins |
---|
| 101 | ================== |
---|
| 102 | |
---|
| 103 | waeup.sirp provides an API to 'plugin' components. Things that should |
---|
| 104 | be setup at creation time of a WAeUP SIRP application can indicate |
---|
| 105 | that by providing a utility providing IWAeUPSIRPPlugin. |
---|
| 106 | |
---|
| 107 | The plugins are looked up by an created app, which then will call the |
---|
| 108 | ``setup()`` method of each plugin. |
---|
| 109 | |
---|
| 110 | >>> from waeup.sirp.interfaces import IWAeUPSIRPPluggable |
---|
| 111 | >>> from zope.component import getAdapters, getUtilitiesFor |
---|
| 112 | >>> sorted(list(getUtilitiesFor(IWAeUPSIRPPluggable))) |
---|
| 113 | [(u'accesscodes', <waeup.sirp.accesscodes...AccessCodePlugin ...)] |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | We can provide a new plugin like this: |
---|
| 117 | |
---|
| 118 | >>> import grok |
---|
| 119 | >>> from waeup.sirp.interfaces import IWAeUPSIRPPluggable |
---|
| 120 | >>> class MyPlugin(grok.GlobalUtility): |
---|
| 121 | ... grok.implements(IWAeUPSIRPPluggable) |
---|
| 122 | ... def setup(self, site, name, logger): |
---|
| 123 | ... print "Setup was called for" |
---|
| 124 | ... print site |
---|
| 125 | ... def update(self, site, name, logger): |
---|
| 126 | ... pass |
---|
| 127 | |
---|
| 128 | When we register the plugin |
---|
| 129 | |
---|
| 130 | >>> grok.testing.grok_component('MyPlugin', MyPlugin) |
---|
| 131 | True |
---|
| 132 | |
---|
| 133 | and setup a new WAeUP SIRP instance, we will get a message: |
---|
| 134 | |
---|
| 135 | >>> from waeup.sirp.app import University |
---|
| 136 | >>> site = University() |
---|
| 137 | Setup was called for |
---|
| 138 | <waeup.sirp.app.University object at 0x...> |
---|
| 139 | |
---|
| 140 | Apparently the plugin can do with the University object whatever it |
---|
| 141 | likes. That's what plugins are for. |
---|