transition now fires TransitionEvent; added more icons and corresponding settings for states
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2556 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
5d022e524e
commit
cd46c0a345
7 changed files with 44 additions and 7 deletions
BIN
browser/icons/cancel.png
Executable file
BIN
browser/icons/cancel.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 792 B |
BIN
browser/icons/delete.png
Executable file
BIN
browser/icons/delete.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
browser/icons/favorite.png
Executable file
BIN
browser/icons/favorite.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
|
@ -64,6 +64,9 @@ class Stateful(object):
|
||||||
sd = self.getStatesDefinition()
|
sd = self.getStatesDefinition()
|
||||||
return sd.getAvailableTransitionsFor(self)
|
return sd.getAvailableTransitionsFor(self)
|
||||||
|
|
||||||
|
def getAvailableTransitionsForUser(self):
|
||||||
|
return self.getAvailableTransitions()
|
||||||
|
|
||||||
def getStatesDefinition(self):
|
def getStatesDefinition(self):
|
||||||
return statesDefinitions.get(self.statesDefinition, None)
|
return statesDefinitions.get(self.statesDefinition, None)
|
||||||
|
|
||||||
|
|
|
@ -22,17 +22,21 @@ State definition implementation.
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from zope.component.interfaces import ObjectEvent
|
||||||
|
from zope.event import notify
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
from cybertools.util.jeep import Jeep
|
from cybertools.util.jeep import Jeep
|
||||||
|
|
||||||
from cybertools.stateful.interfaces import IState, ITransition
|
from cybertools.stateful.interfaces import IState, ITransition
|
||||||
from cybertools.stateful.interfaces import IStatesDefinition
|
from cybertools.stateful.interfaces import IStatesDefinition
|
||||||
|
from cybertools.stateful.interfaces import ITransitionEvent
|
||||||
|
|
||||||
|
|
||||||
class State(object):
|
class State(object):
|
||||||
|
|
||||||
implements(IState)
|
implements(IState)
|
||||||
|
|
||||||
|
icon = None
|
||||||
color = 'blue'
|
color = 'blue'
|
||||||
|
|
||||||
def __init__(self, name, title, transitions, **kw):
|
def __init__(self, name, title, transitions, **kw):
|
||||||
|
@ -82,12 +86,27 @@ class StatesDefinition(object):
|
||||||
if transition not in [t.name for t in self.getAvailableTransitionsFor(obj)]:
|
if transition not in [t.name for t in self.getAvailableTransitionsFor(obj)]:
|
||||||
raise ValueError("Transition '%s' is not reachable from state '%s'."
|
raise ValueError("Transition '%s' is not reachable from state '%s'."
|
||||||
% (transition, obj.getState()))
|
% (transition, obj.getState()))
|
||||||
obj.state = self.transitions[transition].targetState
|
transObject = self.transitions[transition]
|
||||||
|
previousState = obj.state
|
||||||
|
obj.state = transObject.targetState
|
||||||
|
notify(TransitionEvent(obj, transObject, previousState))
|
||||||
|
|
||||||
def getAvailableTransitionsFor(self, obj):
|
def getAvailableTransitionsFor(self, obj):
|
||||||
state = obj.getState()
|
state = obj.getState()
|
||||||
return [self.transitions[t] for t in self.states[state].transitions]
|
return [self.transitions[t] for t in self.states[state].transitions]
|
||||||
|
|
||||||
|
|
||||||
|
# event
|
||||||
|
|
||||||
|
class TransitionEvent(ObjectEvent):
|
||||||
|
|
||||||
|
implements(ITransitionEvent)
|
||||||
|
|
||||||
|
def __init__(self, obj, transition, previousState):
|
||||||
|
super(TransitionEvent, self).__init__(obj)
|
||||||
|
self.transition = transition
|
||||||
|
self.previousState = previousState
|
||||||
|
|
||||||
# dummy default states definition
|
# dummy default states definition
|
||||||
|
|
||||||
defaultSD = StatesDefinition('default',
|
defaultSD = StatesDefinition('default',
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -22,6 +22,7 @@ Interfaces for the `stateful` package.
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from zope.component.interfaces import IObjectEvent
|
||||||
from zope.interface import Interface, Attribute
|
from zope.interface import Interface, Attribute
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,6 +72,12 @@ class IStateful(Interface):
|
||||||
provide the ITransition interface.
|
provide the ITransition interface.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def getAvailableTransitionsForUser():
|
||||||
|
""" Return the transitions for this object that are available for
|
||||||
|
the current user. This is a subset of all available transitions
|
||||||
|
for the current state.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class IHistorizable(Interface):
|
class IHistorizable(Interface):
|
||||||
""" An object that may record history information, e.g. when
|
""" An object that may record history information, e.g. when
|
||||||
|
@ -105,3 +112,10 @@ class IStatesDefinition(Interface):
|
||||||
""" Return the transitions available for this object in its current state.
|
""" Return the transitions available for this object in its current state.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class ITransitionEvent(IObjectEvent):
|
||||||
|
""" Fires when the state of an object is changed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
transition = Attribute('The transition.')
|
||||||
|
previousState = Attribute('The name of the state before the transition.')
|
||||||
|
|
|
@ -33,11 +33,12 @@ from cybertools.stateful.interfaces import IStatesDefinition
|
||||||
@implementer(IStatesDefinition)
|
@implementer(IStatesDefinition)
|
||||||
def simplePublishing():
|
def simplePublishing():
|
||||||
return StatesDefinition('publishing',
|
return StatesDefinition('publishing',
|
||||||
State('private', 'private', ('show', 'archive', 'remove')),
|
State('private', 'private', ('show', 'archive', 'remove'), color='red'),
|
||||||
State('draft', 'draft', ('publish', 'hide', 'archive', 'remove')),
|
State('draft', 'draft', ('publish', 'hide', 'archive', 'remove'),
|
||||||
State('published', 'published', ('retract', 'archive')),
|
color='yellow'),
|
||||||
State('archived', 'archived', ('show', 'remove')),
|
State('published', 'published', ('retract', 'archive'), color='green'),
|
||||||
State('removed', 'removed', ('show',)),
|
State('archived', 'archived', ('show', 'remove'), color='lightblue'),
|
||||||
|
State('removed', 'removed', ('show',), icon='cancel.png'),
|
||||||
Transition('show', 'show', 'draft'),
|
Transition('show', 'show', 'draft'),
|
||||||
Transition('hide', 'hide', 'private'),
|
Transition('hide', 'hide', 'private'),
|
||||||
Transition('publish', 'publish', 'published'),
|
Transition('publish', 'publish', 'published'),
|
||||||
|
|
Loading…
Add table
Reference in a new issue