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