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

Last change on this file since 5486 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
RevLine 
[4920]1:mod:`waeup.sirp.university.coursecontainer` -- Course containers
2*****************************************************************
[4261]3
[4920]4.. module:: waeup.sirp.university.coursecontainer
[4364]5
[4261]6Containers for courses.
7
[5140]8.. :doctest:
9.. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer
[4261]10
[4364]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
[4920]28   :class:`waeup.sirp.university.course.Course`.
[4364]29
[4920]30     >>> from waeup.sirp.university.coursecontainer import CourseContainer
[4364]31     >>> mycontainer = CourseContainer()
32     >>> mycontainer
[4920]33     <waeup.sirp.university.coursecontainer.CourseContainer object at 0x...>
[4364]34
35   Course containers provide `ICourseContainer`:
36
[5005]37     >>> from waeup.sirp.university.interfaces import ICourseContainer
[4364]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
[4920]59      :class:`waeup.sirp.university.course.Course`:
[4364]60
[4920]61        >>> from waeup.sirp.university.coursecontainer import CourseContainer
[4364]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
[4920]70        >>> from waeup.sirp.university.course import Course
[4364]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
[4920]105     <waeup.sirp.university.coursecontainer.CourseContainer object at 0x...>
[4364]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
[4920]112     >>> from waeup.sirp.university.coursecontainer import CourseContainerFactory
[4364]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()
[4920]121     <implementedBy waeup.sirp.university.coursecontainer.CourseContainer>
[4364]122
123
124Examples
125========
126
[4261]127Getting a course container
[4364]128--------------------------
[4261]129
130We can easily create `CourseContainers`:
131
[4920]132    >>> from waeup.sirp.university.coursecontainer import CourseContainer
[4261]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
[4364]138under the name ``waeup.CourseContainer``. Now we can ask for an object
139by calling the appropriate factory:
[4261]140
141    >>> from zope.component import createObject
142    >>> createObject(u'waeup.CourseContainer')
[4920]143    <waeup.sirp.university.coursecontainer.CourseContainer object at 0x...>
[4261]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.