source: main/waeup.kofa/trunk/src/waeup/kofa/university/coursescontainer.txt @ 9142

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

Add more roles and reorganize permissions.

Remove grok.require('waeup.manageUniversity') from grok.Container classes.

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