source: main/waeup.sirp/trunk/src/waeup/sirp/university/coursecontainer.txt @ 6101

Last change on this file since 6101 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: 4.2 KB
Line 
1:mod:`waeup.sirp.university.coursecontainer` -- Course containers
2*****************************************************************
3
4.. module:: waeup.sirp.university.coursecontainer
5
6Containers for courses.
7
8.. :doctest:
9.. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer
10
11
12Content Classes (models and containers)
13=======================================
14
15:class:`CourseContainer`
16------------------------
17
18.. class:: CourseContainer()
19
20   Create a course container instance.
21
22   .. attribute:: grok.implements(ICourseContainer)
23
24   .. attribute:: grok.require('waeup.manageUniversity')
25
26   :class:`CourseContainer` instances are instances of
27   :class:`grok.Container` that hold and manage instances of
28   :class:`waeup.sirp.university.course.Course`.
29
30     >>> from waeup.sirp.university.coursecontainer import CourseContainer
31     >>> mycontainer = CourseContainer()
32     >>> mycontainer
33     <waeup.sirp.university.coursecontainer.CourseContainer object at 0x...>
34
35   Course containers provide `ICourseContainer`:
36
37     >>> from waeup.sirp.university.interfaces import ICourseContainer
38     >>> ICourseContainer.providedBy(mycontainer)
39     True
40
41   We can be sure, that the full interface is supported by the
42   CourseContainer class:
43
44     >>> from zope.interface.verify import verifyClass
45     >>> verifyClass(ICourseContainer, CourseContainer)
46     True
47
48   As normal ``grok.Container``, :class:`CourseContainer` instances
49   can be used like dicts:
50
51     >>> list(mycontainer.keys())
52     []
53
54   .. method:: addCourse(course)
55
56      Add a course.
57
58      *course* must be an instance of
59      :class:`waeup.sirp.university.course.Course`:
60
61        >>> from waeup.sirp.university.coursecontainer import CourseContainer
62        >>> mycontainer = CourseContainer()
63        >>> mycontainer.addCourse('blah')
64        Traceback (most recent call last):
65        ...
66        TypeError: CourseContainers contain only ICourse instances
67
68      The key of added items is the ``code`` attribute:
69
70        >>> from waeup.sirp.university.course import Course
71        >>> mycourse = Course(code='COURSE1')
72        >>> mycontainer.addCourse(mycourse)
73        >>> list(mycontainer.keys())
74        [u'COURSE1']
75
76   .. method:: clear()
77
78      Remove all contained courses:
79
80        >>> len(mycontainer.items())
81        1
82
83        >>> mycontainer.clear()
84        >>> len(mycontainer.items())
85        0
86
87Utilities
88=========
89
90:class:`CourseContainerFactory`
91-------------------------------
92
93.. class:: CourseContainerFactory()
94
95   .. attribute:: grok.name(u'waeup.CourseContainer')
96
97   .. attribute:: grok.implements(IFactory)
98
99   A named utility to deliver new instances of :class:`CourseContainer`
100   without the need to import the implementation before:
101
102     >>> from zope.component import createObject
103     >>> mycoursecontainer = createObject(u'waeup.CourseContainer')
104     >>> mycoursecontainer
105     <waeup.sirp.university.coursecontainer.CourseContainer object at 0x...>
106
107   The factory complies with the specifications from the
108   :class:`IFactory` insterface:
109
110     >>> from zope.interface.verify import verifyClass
111     >>> from zope.component.interfaces import IFactory
112     >>> from waeup.sirp.university.coursecontainer import CourseContainerFactory
113     >>> verifyClass(IFactory, CourseContainerFactory)
114     True
115
116   This means also, that we can get the interfaces of the created
117   object from the factory:
118
119     >>> coursecontainer_factory = CourseContainerFactory()
120     >>> coursecontainer_factory.getInterfaces()
121     <implementedBy waeup.sirp.university.coursecontainer.CourseContainer>
122
123
124Examples
125========
126
127Getting a course container
128--------------------------
129
130We can easily create `CourseContainers`:
131
132    >>> from waeup.sirp.university.coursecontainer import CourseContainer
133    >>> mycontainer = CourseContainer()
134
135
136Another way to get a course container -- without importing the class
137-- is via factories. We registered a factory for course containers
138under the name ``waeup.CourseContainer``. Now we can ask for an object
139by calling the appropriate factory:
140
141    >>> from zope.component import createObject
142    >>> createObject(u'waeup.CourseContainer')
143    <waeup.sirp.university.coursecontainer.CourseContainer object at 0x...>
144
145This way we get a thing that implements ICourseContainer without
146imports or similar.
147
Note: See TracBrowser for help on using the repository browser.