source: main/waeup.sirp/trunk/src/waeup/sirp/university/facultycontainer.txt @ 5015

Last change on this file since 5015 was 5015, checked in by uli, 15 years ago

Update docs.

File size: 5.8 KB
Line 
1:mod:`waeup.sirp.university.facultycontainer` -- Faculty Containers
2*******************************************************************
3
4.. module:: waeup.sirp.university.facultycontainer
5
6Components that represent faculty containers.
7
8:Test-Layer: unit
9
10Before we can create faculty containers, we have to grok the
11:mod:`waeup.sirp` package. This happens automatically in real-world
12use:
13
14    >>> import grok
15    >>> grok.testing.grok('waeup.sirp')
16
17
18Content Classes (models and containers)
19=======================================
20
21:class:`FacultyContainer`
22-------------------------
23
24.. class:: FacultyContainer()
25
26   Create a faculty container:
27
28     >>> from waeup.sirp.university.facultycontainer import FacultyContainer
29     >>> mycontainer = FacultyContainer()
30     >>> mycontainer
31     <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...>
32
33   Another way to create :class:`FacultyContainer` instances is by asking
34   for a factory called ``waeup.FacultyContainer``. This way we can create a
35   faculty without importing a class:
36
37     >>> from zope.component import createObject
38     >>> mycontainer = createObject(u'waeup.FacultyContainer')
39     >>> mycontainer
40     <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...>
41
42   :class:`FacultyContainer` instances have the attributes required by the
43   `IFacultyContainer` interface:
44
45     >>> from waeup.sirp.university.interfaces import IFacultyContainer
46     >>> IFacultyContainer.providedBy(mycontainer)
47     True
48
49     >>> from zope.interface.verify import verifyObject
50     >>> verifyObject(IFacultyContainer, mycontainer)
51     True
52
53   .. method:: addFaculty(faculty)
54
55      Add a faculty into this container. Added objects are checked and
56      only `IFaculty` objects accepted:
57
58        >>> mycontainer.addFaculty(object())
59        Traceback (most recent call last):
60        ...
61        TypeError: FacultyContainers contain only IFaculty instances
62
63        >>> list(mycontainer.values())
64        []
65
66      Regular faculties are accepted:
67
68        >>> from waeup.sirp.university.faculty import Faculty
69        >>> mycontainer.addFaculty(Faculty(title='Physics',
70        ...                                code='FP'))
71
72        >>> list(mycontainer.items())
73        [(u'FP', <waeup.sirp.university.faculty.Faculty object at 0x...>)]
74
75   .. method:: clear()
76
77      Remove all departments from this faculty:
78
79        >>> mycontainer.clear()
80        >>> list(mycontainer.items())
81        []
82
83
84Utilities
85=========
86
87:class:`AcademicsPlugin`
88------------------------
89
90.. class:: AcademicsPlugin()
91
92   .. attribute:: grok.implements(IWAeUPSIRPPluggable)
93
94   This plugin component tells under which name (``faculties``) an
95   instance of academics stuff should be created in plain WAeUP SIRP
96   instances. It also tells the factory name for FacultyContainer
97   instances, which serve as root object for academics stuff in WAeUP
98   SIRP apps.
99
100
101:class:`FacultyContainerFactory`
102--------------------------------
103
104.. class:: FacultyContainerFactory()
105
106   .. attribute:: grok.name(u'waeup.FacultyContainer')
107
108   .. attribute:: grok.implements(IFactoryContainer)
109
110   A named utility to deliver new instances of :class:`FacultyContainer`
111   without the need to import the implementation before:
112
113     >>> from zope.component import createObject
114     >>> mycontainer = createObject(u'waeup.FacultyContainer')
115     >>> mycontainer
116     <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...>
117
118   The factory complies with the specifications from the
119   :class:`IFactory` insterface:
120
121     >>> from zope.interface.verify import verifyClass
122     >>> from zope.component.interfaces import IFactory
123     >>> from waeup.sirp.university.facultycontainer import (
124     ...   FacultyContainerFactory)
125     >>> verifyClass(IFactory, FacultyContainerFactory)
126     True
127
128   This means also, that we can get the interfaces of the created
129   object from the factory:
130
131     >>> fac_container_factory = FacultyContainerFactory()
132     >>> fac_container_factory.getInterfaces()
133     <implementedBy waeup.sirp.university.facultycontainer.FacultyContainer>
134
135Examples
136========
137
138We can easily create `FacultyContainers`:
139
140    >>> from waeup.sirp.university.facultycontainer import FacultyContainer
141    >>> mycontainer = FacultyContainer()
142
143Faculty containers provide `IFacultyContainer`:
144
145    >>> from waeup.sirp.university.interfaces import IFacultyContainer
146    >>> IFacultyContainer.providedBy(mycontainer)
147    True
148
149Another way to get a faculty container -- without importing the class
150-- is via factories. We registered a factory for faculty containers
151under the name ``waeup.facultycontainer``:
152
153    >>> from zope.component import createObject
154    >>> createObject(u'waeup.FacultyContainer')
155    <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...>
156
157This way we get a thing that implements IFacultyContainer without
158imports or similar.
159
160We can be sure, that the full interface is supported by the
161FacultyContainer class::
162
163    >>> from zope.interface.verify import verifyClass
164    >>> verifyClass(IFacultyContainer, FacultyContainer)
165    True
166
167
168Storing things in faculty containers
169====================================
170
171We can, of course, store things in a faculty container. But when we
172really store an object, then it must be a faculty::
173
174    >>> mycontainer.addFaculty(42)
175    Traceback (most recent call last):
176    ...
177    TypeError: FacultyContainers contain only IFaculty instances
178
179Okay, so we have to get a faculty first::
180
181    >>> from waeup.sirp.university.faculty import Faculty
182    >>> myfaculty = Faculty()
183
184We can add this faculty to our container::
185
186    >>> mycontainer.addFaculty(myfaculty)
187
188We get back the key, under which the faculty was stored. It will be
189some string, but there is no guarantee at all, how this key looks
190like. It might be a string of integers, a name or whatever; you cannot
191know before.
192
Note: See TracBrowser for help on using the repository browser.