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

Last change on this file since 7022 was 6979, checked in by Henrik Bettermann, 13 years ago

Remove unused clear method which was even wrong.

File size: 5.5 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
70
71Utilities
72=========
73
[5015]74:class:`AcademicsPlugin`
75------------------------
76
77.. class:: AcademicsPlugin()
78
79   .. attribute:: grok.implements(IWAeUPSIRPPluggable)
80
81   This plugin component tells under which name (``faculties``) an
82   instance of academics stuff should be created in plain WAeUP SIRP
83   instances. It also tells the factory name for FacultyContainer
84   instances, which serve as root object for academics stuff in WAeUP
85   SIRP apps.
86
87
[4977]88:class:`FacultyContainerFactory`
89--------------------------------
90
91.. class:: FacultyContainerFactory()
92
93   .. attribute:: grok.name(u'waeup.FacultyContainer')
94
95   .. attribute:: grok.implements(IFactoryContainer)
96
97   A named utility to deliver new instances of :class:`FacultyContainer`
98   without the need to import the implementation before:
99
100     >>> from zope.component import createObject
101     >>> mycontainer = createObject(u'waeup.FacultyContainer')
102     >>> mycontainer
103     <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...>
104
105   The factory complies with the specifications from the
106   :class:`IFactory` insterface:
107
108     >>> from zope.interface.verify import verifyClass
109     >>> from zope.component.interfaces import IFactory
110     >>> from waeup.sirp.university.facultycontainer import (
111     ...   FacultyContainerFactory)
112     >>> verifyClass(IFactory, FacultyContainerFactory)
113     True
114
115   This means also, that we can get the interfaces of the created
116   object from the factory:
117
118     >>> fac_container_factory = FacultyContainerFactory()
119     >>> fac_container_factory.getInterfaces()
120     <implementedBy waeup.sirp.university.facultycontainer.FacultyContainer>
121
122Examples
123========
124
125We can easily create `FacultyContainers`:
126
[4920]127    >>> from waeup.sirp.university.facultycontainer import FacultyContainer
[3923]128    >>> mycontainer = FacultyContainer()
129
[4080]130Faculty containers provide `IFacultyContainer`:
[3923]131
[5005]132    >>> from waeup.sirp.university.interfaces import IFacultyContainer
[3923]133    >>> IFacultyContainer.providedBy(mycontainer)
134    True
135
[4080]136Another way to get a faculty container -- without importing the class
137-- is via factories. We registered a factory for faculty containers
[4977]138under the name ``waeup.facultycontainer``:
[3923]139
[4080]140    >>> from zope.component import createObject
141    >>> createObject(u'waeup.FacultyContainer')
[4920]142    <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...>
[3923]143
144This way we get a thing that implements IFacultyContainer without
145imports or similar.
146
147We can be sure, that the full interface is supported by the
148FacultyContainer class::
149
150    >>> from zope.interface.verify import verifyClass
151    >>> verifyClass(IFacultyContainer, FacultyContainer)
152    True
153
154
155Storing things in faculty containers
156====================================
157
158We can, of course, store things in a faculty container. But when we
159really store an object, then it must be a faculty::
160
161    >>> mycontainer.addFaculty(42)
162    Traceback (most recent call last):
163    ...
164    TypeError: FacultyContainers contain only IFaculty instances
165
166Okay, so we have to get a faculty first::
167
[4920]168    >>> from waeup.sirp.university.faculty import Faculty
[3923]169    >>> myfaculty = Faculty()
170
171We can add this faculty to our container::
172
173    >>> mycontainer.addFaculty(myfaculty)
174
[3924]175We get back the key, under which the faculty was stored. It will be
176some string, but there is no guarantee at all, how this key looks
177like. It might be a string of integers, a name or whatever; you cannot
178know before.
[4162]179
Note: See TracBrowser for help on using the repository browser.