source: main/waeup.sirp/trunk/src/waeup/sirp/university/certificatescontainer.txt @ 10222

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

Rename certificatecontainer, coursecontainer and facultycontainer. Now we have e.g. a container for faculties. Synonyms are 'facultiescontainer', 'faculties', 'academics' or 'Academic Section'. The faculty container is the faculty itself which contains the departments.

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