[4920] | 1 | :mod:`waeup.sirp.app` -- central components for a WAeUP portal |
---|
| 2 | ************************************************************** |
---|
[3933] | 3 | |
---|
[5140] | 4 | .. :doctest: |
---|
| 5 | .. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer |
---|
[3933] | 6 | |
---|
[4920] | 7 | .. module:: waeup.sirp.app |
---|
[3933] | 8 | |
---|
[4273] | 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 |
---|
[4920] | 23 | `waeup.sirp.interfaces.IFacultyContainer`. |
---|
[4273] | 24 | |
---|
| 25 | |
---|
[3933] | 26 | Creating `University` instances |
---|
| 27 | =============================== |
---|
| 28 | |
---|
[4273] | 29 | As :class:`University` instances make use of the Zope Component |
---|
| 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 | |
---|
[4273] | 36 | Now we can import the :class:`University` class and create an |
---|
| 37 | instance: |
---|
[3933] | 38 | |
---|
[4920] | 39 | >>> from waeup.sirp.app import University |
---|
[3933] | 40 | >>> myuniversity = University() |
---|
| 41 | >>> myuniversity |
---|
[4920] | 42 | <waeup.sirp.app.University object at 0x...> |
---|
[3933] | 43 | |
---|
| 44 | Instances of `University` comply with the interface |
---|
[4920] | 45 | `waeup.sirp.interfaces.IUniversity`: |
---|
[3933] | 46 | |
---|
| 47 | >>> from zope.interface.verify import verifyClass |
---|
[4920] | 48 | >>> from waeup.sirp.interfaces import IUniversity |
---|
[3933] | 49 | >>> verifyClass(IUniversity, University) |
---|
| 50 | True |
---|
| 51 | |
---|
[4273] | 52 | A freshly created instance provides the attributes promised by the |
---|
| 53 | interface: |
---|
[3933] | 54 | |
---|
[4920] | 55 | >>> from waeup.sirp.app import University |
---|
[3933] | 56 | >>> myuniversity = University() |
---|
| 57 | >>> myuniversity.name |
---|
| 58 | u'Sample University' |
---|
| 59 | |
---|
[4748] | 60 | >>> myuniversity['faculties'] |
---|
[4920] | 61 | <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...> |
---|