From 7cd7a574c0e34d5a6d1164c050204a05cc04d637 Mon Sep 17 00:00:00 2001 From: helmutm Date: Sun, 27 Apr 2008 14:27:33 +0000 Subject: [PATCH] add transition event git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2559 fd906abe-77d9-0310-91a1-e0d9ade77398 --- stateful/base.py | 19 ++++++++++++++++++- stateful/definition.py | 1 + stateful/interfaces.py | 12 ++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/stateful/base.py b/stateful/base.py index 54d11a4..cbbb304 100644 --- a/stateful/base.py +++ b/stateful/base.py @@ -24,10 +24,11 @@ $Id$ from persistent.interfaces import IPersistent from persistent.mapping import PersistentMapping +from zope import component from zope.component import adapts from zope.interface import implements -from cybertools.stateful.interfaces import IStateful +from cybertools.stateful.interfaces import IStateful, IStatefulIndexInfo from cybertools.stateful.definition import statesDefinitions @@ -94,3 +95,19 @@ class StatefulAdapter(Stateful): statesAttr[self.statesDefinition] = value state = property(getState, setState) + +class IndexInfo(object): + + implements(IStatefulIndexInfo) + + availableStatesDefinitions = [] # to be overwritten by subclass! + + def __init__(self, context): + self.context = context + + @property + def tokens(self): + for std in self.availableStatesDefinitions: + stf = component.getAdapter(self.context, IStateful, name=std) + yield ':'.join((std, stf.state)) + diff --git a/stateful/definition.py b/stateful/definition.py index 131413d..c6f6027 100644 --- a/stateful/definition.py +++ b/stateful/definition.py @@ -107,6 +107,7 @@ class TransitionEvent(ObjectEvent): self.transition = transition self.previousState = previousState + # dummy default states definition defaultSD = StatesDefinition('default', diff --git a/stateful/interfaces.py b/stateful/interfaces.py index 085bbe6..4a765c1 100644 --- a/stateful/interfaces.py +++ b/stateful/interfaces.py @@ -113,6 +113,18 @@ class IStatesDefinition(Interface): """ +class IStatefulIndexInfo(Interface): + """ Provide a list of tokens to be used for index the states + of an object in the catalog. + """ + + tokens = Attribute('A sequence of strings to be used for indexing the ' + 'states; format: [:, ...].') + + availableStatesDefinitions = Attribute('A sequence of strings with the ' + 'names of all states definitions currently available.') + + class ITransitionEvent(IObjectEvent): """ Fires when the state of an object is changed. """