[4289] | 1 | """Containers for certificates. |
---|
| 2 | """ |
---|
| 3 | import grok |
---|
| 4 | from waeup.interfaces import ICertificateContainer, ICertificate |
---|
| 5 | from zope.component.interfaces import IFactory |
---|
[4365] | 6 | from zope.interface import implementedBy |
---|
[4289] | 7 | |
---|
| 8 | class CertificateContainer(grok.Container): |
---|
| 9 | """See interfaces for description. |
---|
| 10 | """ |
---|
| 11 | grok.implements(ICertificateContainer) |
---|
| 12 | grok.require('waeup.manageUniversity') |
---|
| 13 | |
---|
| 14 | def addCertificate(self, certificate): |
---|
| 15 | if not ICertificate.providedBy(certificate): |
---|
| 16 | raise TypeError('CertificateContainers contain only ' |
---|
| 17 | 'ICertificate instances') |
---|
| 18 | self[certificate.code] = certificate |
---|
| 19 | return |
---|
| 20 | |
---|
| 21 | def clear(self): |
---|
| 22 | keys = self.keys() |
---|
| 23 | for key in keys: |
---|
| 24 | del self[key] |
---|
| 25 | |
---|
| 26 | class CertificateContainerFactory(grok.GlobalUtility): |
---|
| 27 | """A factory for certificate containers. |
---|
| 28 | """ |
---|
| 29 | grok.implements(IFactory) |
---|
| 30 | grok.name(u'waeup.CertificateContainer') |
---|
| 31 | title = u"Create a new certificate container.", |
---|
| 32 | description = u"This factory instantiates new certificate containers." |
---|
| 33 | |
---|
[4366] | 34 | def __call__(self, *args, **kw): |
---|
| 35 | return CertificateContainer(*args, **kw) |
---|
[4289] | 36 | |
---|
| 37 | def getInterfaces(self): |
---|
| 38 | return implementedBy(CertificateContainer) |
---|