source: main/waeup.sirp/trunk/src/waeup/sirp/university/certificatecontainer.txt @ 5013

Last change on this file since 5013 was 5005, checked in by uli, 15 years ago

Fix references to academics stuff interfaces. This is the first step to make academics stuff pluggable.

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