[7811] | 1 | :mod:`waeup.kofa.university.certificatescontainer` -- Certificate containers |
---|
[7333] | 2 | **************************************************************************** |
---|
[4367] | 3 | |
---|
[7811] | 4 | .. module:: waeup.kofa.university.certificatescontainer |
---|
[4367] | 5 | |
---|
| 6 | Containers for certificates. |
---|
| 7 | |
---|
[5140] | 8 | .. :doctest: |
---|
[7819] | 9 | .. :layer: waeup.kofa.testing.KofaUnitTestLayer |
---|
[4367] | 10 | |
---|
| 11 | |
---|
| 12 | Content 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 | |
---|
| 24 | .. attribute:: grok.require('waeup.manageUniversity') |
---|
| 25 | |
---|
[7333] | 26 | :class:`CertificatesContainer` instances are instances of |
---|
[4367] | 27 | :class:`grok.Container` that hold and manage instances of |
---|
[7811] | 28 | :class:`waeup.kofa.university.certificate.Certificate`. |
---|
[4367] | 29 | |
---|
[7811] | 30 | >>> from waeup.kofa.university.certificatescontainer import CertificatesContainer |
---|
[7333] | 31 | >>> mycontainer = CertificatesContainer() |
---|
[4367] | 32 | >>> mycontainer |
---|
[7811] | 33 | <waeup.kofa.university.certificatescontainer.CertificatesContainer object at 0x...> |
---|
[4367] | 34 | |
---|
[7333] | 35 | Certificate containers provide `ICertificatesContainer`: |
---|
[4367] | 36 | |
---|
[7811] | 37 | >>> from waeup.kofa.university.interfaces import ICertificatesContainer |
---|
[7333] | 38 | >>> ICertificatesContainer.providedBy(mycontainer) |
---|
[4367] | 39 | True |
---|
| 40 | |
---|
| 41 | We can be sure, that the full interface is supported by the |
---|
[7333] | 42 | CertificatesContainer class: |
---|
[4367] | 43 | |
---|
| 44 | >>> from zope.interface.verify import verifyClass |
---|
[7333] | 45 | >>> verifyClass(ICertificatesContainer, CertificatesContainer) |
---|
[4367] | 46 | True |
---|
| 47 | |
---|
[7333] | 48 | As normal ``grok.Container``, :class:`CertificatesContainer` instances |
---|
[4367] | 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 |
---|
[7811] | 59 | :class:`waeup.kofa.university.certificate.Certificate`: |
---|
[4367] | 60 | |
---|
[7811] | 61 | >>> from waeup.kofa.university.certificatescontainer import ( |
---|
[7333] | 62 | ... CertificatesContainer) |
---|
| 63 | >>> mycontainer = CertificatesContainer() |
---|
[4367] | 64 | >>> mycontainer.addCertificate('blah') |
---|
| 65 | Traceback (most recent call last): |
---|
| 66 | ... |
---|
[7333] | 67 | TypeError: CertificatesContainers contain only ICertificate instances |
---|
[4367] | 68 | |
---|
| 69 | The key of added items is the ``code`` attribute: |
---|
| 70 | |
---|
[7811] | 71 | >>> from waeup.kofa.university.certificate import Certificate |
---|
[4367] | 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 | |
---|
| 88 | Utilities |
---|
| 89 | ========= |
---|
| 90 | |
---|
[7333] | 91 | :class:`CertificatesContainerFactory` |
---|
| 92 | ------------------------------------- |
---|
[4367] | 93 | |
---|
[7333] | 94 | .. class:: CertificatesContainerFactory() |
---|
[4367] | 95 | |
---|
[7333] | 96 | .. attribute:: grok.name(u'waeup.CertificatesContainer') |
---|
[4367] | 97 | |
---|
| 98 | .. attribute:: grok.implements(IFactory) |
---|
| 99 | |
---|
[7333] | 100 | A named utility to deliver new instances of :class:`CertificatesContainer` |
---|
[4367] | 101 | without the need to import the implementation before: |
---|
| 102 | |
---|
| 103 | >>> from zope.component import createObject |
---|
[7333] | 104 | >>> mycertificatescontainer = createObject(u'waeup.CertificatesContainer') |
---|
| 105 | >>> mycertificatescontainer |
---|
[7811] | 106 | <waeup.kofa.university.certificatescontainer.CertificatesContainer object at 0x...> |
---|
[4367] | 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 |
---|
[7811] | 113 | >>> from waeup.kofa.university.certificatescontainer import ( |
---|
[7333] | 114 | ... CertificatesContainerFactory) |
---|
| 115 | >>> verifyClass(IFactory, CertificatesContainerFactory) |
---|
[4367] | 116 | True |
---|
| 117 | |
---|
| 118 | This means also, that we can get the interfaces of the created |
---|
| 119 | object from the factory: |
---|
| 120 | |
---|
[7333] | 121 | >>> certificatescontainer_factory = CertificatesContainerFactory() |
---|
| 122 | >>> certificatescontainer_factory.getInterfaces() |
---|
[7811] | 123 | <implementedBy waeup.kofa.university.certificatescontainer.CertificatesContainer> |
---|
[4367] | 124 | |
---|
| 125 | |
---|
| 126 | Examples |
---|
| 127 | ======== |
---|
| 128 | |
---|
| 129 | Getting a certificate container |
---|
| 130 | ------------------------------- |
---|
| 131 | |
---|
[7333] | 132 | We can easily create `CertificatesContainers`: |
---|
[4367] | 133 | |
---|
[7811] | 134 | >>> from waeup.kofa.university.certificatescontainer import CertificatesContainer |
---|
[7333] | 135 | >>> mycontainer = CertificatesContainer() |
---|
[4367] | 136 | |
---|
| 137 | |
---|
| 138 | Another way to get a certificate container -- without importing the |
---|
| 139 | class -- is via factories. We registered a factory for certificate |
---|
[7333] | 140 | containers under the name ``waeup.CertificatesContainer``. Now we can |
---|
[4367] | 141 | ask for an object by calling the appropriate factory: |
---|
| 142 | |
---|
| 143 | >>> from zope.component import createObject |
---|
[7333] | 144 | >>> createObject(u'waeup.CertificatesContainer') |
---|
[7811] | 145 | <waeup.kofa.university.certificatescontainer.CertificatesContainer object at 0x...> |
---|
[4367] | 146 | |
---|
[7333] | 147 | This way we get a thing that implements ICertificatesContainer without |
---|
[4367] | 148 | imports or similar. |
---|
| 149 | |
---|