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

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

Update all unit tests that use the ZCA to run inside the new unit test layer.

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