1 | :mod:`waeup.app` -- central components for a WAeUP portal |
---|
2 | ********************************************************* |
---|
3 | |
---|
4 | :Test-Layer: unit |
---|
5 | |
---|
6 | .. module:: waeup.app |
---|
7 | |
---|
8 | .. class:: University |
---|
9 | |
---|
10 | The main WAeUP application object is given with |
---|
11 | :class:`University`. It provides the main containers as faculties, |
---|
12 | hostels, etc. |
---|
13 | |
---|
14 | .. attribute:: name |
---|
15 | |
---|
16 | A string. The name of a university. |
---|
17 | |
---|
18 | .. attribute:: faculties |
---|
19 | |
---|
20 | An arbitrary object containing "faculties". In the case of |
---|
21 | `University` it is a container of type |
---|
22 | `waeup.interfaces.IFacultyContainer`. |
---|
23 | |
---|
24 | |
---|
25 | Creating `University` instances |
---|
26 | =============================== |
---|
27 | |
---|
28 | As :class:`University` instances make use of the Zope Component |
---|
29 | Architecture (ZCA), we have to setup the basic component registries, |
---|
30 | before we can create instances. We do this by simply grokking the |
---|
31 | whole :mod:`waeup` package. This way all interfaces, utilities and adapters |
---|
32 | defined in the package are looked up and registered with the global |
---|
33 | registries: |
---|
34 | |
---|
35 | >>> import grok |
---|
36 | >>> grok.testing.grok('waeup') |
---|
37 | |
---|
38 | Now we can import the :class:`University` class and create an |
---|
39 | instance: |
---|
40 | |
---|
41 | >>> from waeup.app import University |
---|
42 | >>> myuniversity = University() |
---|
43 | >>> myuniversity |
---|
44 | <waeup.app.University object at 0x...> |
---|
45 | |
---|
46 | Instances of `University` comply with the interface |
---|
47 | `waeup.interfaces.IUniversity`: |
---|
48 | |
---|
49 | >>> from zope.interface.verify import verifyClass |
---|
50 | >>> from waeup.interfaces import IUniversity |
---|
51 | >>> verifyClass(IUniversity, University) |
---|
52 | True |
---|
53 | |
---|
54 | A freshly created instance provides the attributes promised by the |
---|
55 | interface: |
---|
56 | |
---|
57 | >>> from waeup.app import University |
---|
58 | >>> myuniversity = University() |
---|
59 | >>> myuniversity.name |
---|
60 | u'Sample University' |
---|
61 | |
---|
62 | >>> myuniversity['faculties'] |
---|
63 | <waeup.university.facultycontainer.FacultyContainer object at 0x...> |
---|