def getTerm(self, value): if self.pt is None: # no portal tool, see __init__ return SimpleTerm(value) else: return super(PMR2IndexesVocab, self).getTerm(value) def __contains__(self, terms): if self.pt is None: # no portal tool, see __init__ return True else: return super(PMR2IndexesVocab, self).__contains__(terms) PMR2IndexesVocabFactory = vocab_factory(PMR2IndexesVocab) class ExposureFileAnnotatorVocab(SimpleVocabulary): zope.interface.implements(IVocabulary) def __init__(self, context=None): """\ This can be registered without a context since the utilities are generally not inserted during runtime (thus no need to regenerate this list all the time). """ self.context = context terms = self._buildTerms()
from pmr2.app.factory import vocab_factory from morre.pmr2.interfaces import IMorreServer class FeaturesVocab(SimpleVocabulary): zope.interface.implements(IVocabulary) def __init__(self, context=None): self.context = context terms = self._buildTerms() super(FeaturesVocab, self).__init__(terms) def _buildTerms(self): server = zope.component.queryUtility(IMorreServer) if server is None: return [] features = sorted(server.getFeatures()) terms = [SimpleTerm(i, i, i) for i in features] return terms def getTerm(self, value): try: return super(FeaturesVocab, self).getTerm(value) except LookupError: pass return SimpleTerm(None, None, value) FeaturesVocabFactory = vocab_factory(FeaturesVocab)
from pmr2.app.workspace.interfaces import IWorkspace, IWorkspaceListing from pmr2.app.workspace.interfaces import IStorageUtility, IStorage from pmr2.app.workspace.interfaces import ICurrentCommitIdProvider class WorkspaceDirObjListVocab(SimpleVocabulary): def __init__(self, context): self.context = context listing = zope.component.getAdapter(context, IWorkspaceListing) values = listing() terms = [SimpleTerm(i, i[0]) for i in values] super(WorkspaceDirObjListVocab, self).__init__(terms) WorkspaceDirObjListVocabFactory = vocab_factory(WorkspaceDirObjListVocab) class ManifestListVocab(SimpleVocabulary): def __init__(self, context): self.context = context wks = self.acquireWorkspace() self.storage = zope.component.getAdapter(wks, IStorage) commit_id = self.acquireCommitId() if commit_id: self.storage.checkout(commit_id) values = self.storage.files() values.sort()
values = [(i[0], i[0], i[1].title) for i in zope.component.getUtilitiesFor(ICitationFormat)] except: values = [] # XXX wrong terms = [SimpleTerm(*v) for v in values] super(CitationFormat, self).__init__(terms) def getTerm(self, value): try: return super(CitationFormat, self).getTerm(value) except LookupError: # should log the no longer registered utility. return SimpleTerm(value) CitationFormatVocabFactory = vocab_factory(CitationFormat) class LicenseType(SimpleVocabulary): """ Retrieves a list of License documents stored within the CMS. """ def __init__(self, context): self.context = context self.pt = None try: ctx = self.context # Since this is primarily used within notes, we check to see # whether to pass its parent (the ExposureFile) to get the # list of licenses.
import zope.interface import zope.component from zope.schema.interfaces import IVocabulary, IVocabularyFactory, ISource from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from pmr2.app.factory import vocab_factory class SimpleCurationValueVocab(SimpleVocabulary): """\ Simple placeholder vocabulary to loosen up coupling of too many concepts. """ def __init__(self, context): self.context = context values = ( ('c0', u'0 star'), ('c1', u'1 star'), ('c2', u'2 star'), ('c3', u'3 star'), ) terms = [SimpleTerm(i, title=j) for i, j in values] super(SimpleCurationValueVocab, self).__init__(terms) SimpleCurationValueVocabFactory = vocab_factory(SimpleCurationValueVocab)