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