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