source: main/waeup.kofa/trunk/src/waeup/kofa/university/certificatescontainer.txt @ 11018

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