"""Containers for certificates. """ import grok from waeup.sirp.interfaces import ICertificateContainer, ICertificate from zope.component.interfaces import IFactory from zope.interface import implementedBy class CertificateContainer(grok.Container): """See interfaces for description. """ grok.implements(ICertificateContainer) grok.require('waeup.manageUniversity') def addCertificate(self, certificate): if not ICertificate.providedBy(certificate): raise TypeError('CertificateContainers contain only ' 'ICertificate instances') self[certificate.code] = certificate return def clear(self): keys = self.keys() for key in keys: del self[key] class CertificateContainerFactory(grok.GlobalUtility): """A factory for certificate containers. """ grok.implements(IFactory) grok.name(u'waeup.CertificateContainer') title = u"Create a new certificate container.", description = u"This factory instantiates new certificate containers." def __call__(self, *args, **kw): return CertificateContainer(*args, **kw) def getInterfaces(self): return implementedBy(CertificateContainer)