- improve 'move' and 'delegate' actions: create new run, store source and

target work items, keep state when moving


git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@4203 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2011-03-17 16:23:49 +00:00
parent bf8a85453c
commit ff389c1b2f
3 changed files with 62 additions and 25 deletions

View file

@ -48,25 +48,33 @@ def workItemStates():
('plan', 'accept', 'start', 'work', 'finish', 'delegate', ('plan', 'accept', 'start', 'work', 'finish', 'delegate',
'move', 'cancel', 'modify'), color='red'), 'move', 'cancel', 'modify'), color='red'),
State('accepted', 'accepted', State('accepted', 'accepted',
('plan', 'accept', 'start', 'work', 'finish', 'cancel', 'modify'), ('plan', 'accept', 'start', 'work', 'finish',
'move', 'cancel', 'modify'),
color='yellow'), color='yellow'),
State('running', 'running', State('running', 'running',
('work', 'finish', 'cancel', 'modify'), ('work', 'finish', 'move', 'cancel', 'modify'),
color='orange'), color='orange'),
State('done', 'done', State('done', 'done',
('plan', 'accept', 'start', 'work', 'finish', 'delegate', ('plan', 'accept', 'start', 'work', 'finish', 'delegate',
'cancel', 'modify'), color='lightgreen'), 'move', 'cancel', 'modify'), color='lightgreen'),
State('finished', 'finished', State('finished', 'finished',
('plan', 'accept', 'start', 'work', 'finish', 'modify', 'close'), ('plan', 'accept', 'start', 'work', 'finish',
'move', 'modify', 'close'),
color='green'), color='green'),
State('cancelled', 'cancelled', State('cancelled', 'cancelled',
('plan', 'accept', 'start', 'work', 'modify', 'close'), ('plan', 'accept', 'start', 'work', 'move', 'modify', 'close'),
color='grey'), color='grey'),
State('closed', 'closed', (), color='lightblue'), State('closed', 'closed', (), color='lightblue'),
# not directly reachable states: # not directly reachable states:
State('delegated', 'delegated', (), color='purple'), State('delegated', 'delegated',
('plan', 'accept', 'start', 'work', 'finish', 'close', 'delegate',
'move', 'cancel', 'modify'),
color='purple'),
State('delegated_x', 'delegated', (), color='purple'), State('delegated_x', 'delegated', (), color='purple'),
State('moved', 'moved', (), color='grey'), State('moved', 'moved',
('plan', 'accept', 'start', 'work', 'finish', 'close', 'delegate',
'move', 'cancel', 'modify'),
color='grey'),
State('moved_x', 'moved', (), color='grey'), State('moved_x', 'moved', (), color='grey'),
State('replaced', 'replaced', (), color='grey'), State('replaced', 'replaced', (), color='grey'),
State('planned_x', 'planned', (), color='red'), State('planned_x', 'planned', (), color='red'),
@ -201,7 +209,7 @@ class WorkItem(Stateful, Track):
delegated = self delegated = self
self.setData(ignoreParty=True, **kw) self.setData(ignoreParty=True, **kw)
else: else:
if self.state in ('planned', 'accepted', 'done'): if self.state in ('planned', 'accepted', 'delegated', 'moved', 'done'):
self.state = self.state + '_x' self.state = self.state + '_x'
self.reindex('state') self.reindex('state')
xkw = dict(kw) xkw = dict(kw)
@ -209,22 +217,26 @@ class WorkItem(Stateful, Track):
delegated = self.createNew('delegate', userName, ignoreParty=True, **xkw) delegated = self.createNew('delegate', userName, ignoreParty=True, **xkw)
delegated.state = 'delegated' delegated.state = 'delegated'
delegated.reindex('state') delegated.reindex('state')
new = delegated.createNew('plan', userName, **kw) new = delegated.createNew('plan', userName, runId=0, **kw)
new.data['source'] = delegated.name
new.doTransition('plan') new.doTransition('plan')
new.reindex('state') new.reindex('state')
delegated.data['target'] = new.name
return new return new
def move(self, userName, **kw): def move(self, userName, **kw):
if self.state in ('planned', 'accepted', 'done'):
self.state = self.state + '_x'
self.reindex('state')
moved = self.createNew('move', userName, **kw) moved = self.createNew('move', userName, **kw)
moved.state = 'moved' moved.state = 'moved'
moved.reindex('state') moved.reindex('state')
task = kw.pop('task', None) task = kw.pop('task', None)
new = moved.createNew('plan', userName, taskId=task, **kw) new = moved.createNew(None, userName, taskId=task, runId=0, **kw)
new.doTransition('plan') new.data['source'] = moved.name
new.state = self.state
new.reindex('state') new.reindex('state')
moved.data['target'] = new.name
if self.state in ('planned', 'accepted', 'delegated', 'moved', 'done'):
self.state = self.state + '_x'
self.reindex('state')
return new return new
def close(self, userName, **kw): def close(self, userName, **kw):
@ -235,7 +247,7 @@ class WorkItem(Stateful, Track):
new.reindex('state') new.reindex('state')
getParent(self).stopRun(runId=self.runId, finish=True) getParent(self).stopRun(runId=self.runId, finish=True)
for item in self.currentWorkItems: for item in self.currentWorkItems:
if item.state in ('planned', 'accepted', 'done', 'delegated'): if item.state in ('planned', 'accepted', 'done', 'delegated', 'moved'):
item.state = item.state + '_x' item.state = item.state + '_x'
item.reindex('state') item.reindex('state')
return new return new
@ -263,8 +275,10 @@ class WorkItem(Stateful, Track):
if start and end and end < start: if start and end and end < start:
data['end'] = start data['end'] = start
def createNew(self, action, userName, taskId=None, copyData=None, **kw): def createNew(self, action, userName, taskId=None, copyData=None,
runId=None, **kw):
taskId = taskId or self.taskId taskId = taskId or self.taskId
runId = runId is None and self.runId or runId
if copyData is None: if copyData is None:
copyData = self.initAttributes copyData = self.initAttributes
newData = {} newData = {}
@ -279,7 +293,7 @@ class WorkItem(Stateful, Track):
if v not in (None, _not_found): if v not in (None, _not_found):
newData[k] = v newData[k] = v
workItems = IWorkItems(getParent(self)) workItems = IWorkItems(getParent(self))
new = workItems.add(taskId, userName, self.runId, **newData) new = workItems.add(taskId, userName, runId, **newData)
return new return new
def replace(self, other, keepState=False): def replace(self, other, keepState=False):

View file

@ -160,8 +160,8 @@ delegated so that it may be selected by queries.
<WorkItem ['001', 2, 'john', '2008-12-22 19:33', 'delegated']: <WorkItem ['001', 2, 'john', '2008-12-22 19:33', 'delegated']:
{'start': 1229970800, 'created': ..., 'creator': 'john'}> {'start': 1229970800, 'created': ..., 'creator': 'john'}>
>>> wi08 >>> wi08
<WorkItem ['001', 2, 'annie', '2008-12-22 19:33', 'planned']: <WorkItem ['001', 3, 'annie', '2008-12-22 19:33', 'planned']:
{'start': 1229970800, 'created': ..., 'creator': 'john'}> {'start': 1229970800, 'created': ..., 'source': '0000007', 'creator': 'john'}>
>>> len(list(workItems)) >>> len(list(workItems))
8 8
@ -179,13 +179,22 @@ Note that nevertheless only the last work item of a run may be modified.
>>> wi09 = wi08.doAction('modify', 'annie', duration=3600) >>> wi09 = wi08.doAction('modify', 'annie', duration=3600)
>>> wi08 >>> wi08
<WorkItem ['001', 2, 'annie', '2008-12-22 19:33', 'replaced']: <WorkItem ['001', 3, 'annie', '2008-12-22 19:33', 'replaced']:
{'start': 1229970800, 'created': ..., 'creator': 'john'}> {'start': 1229970800, 'created': ..., 'creator': 'john'}>
>>> wi09 >>> wi09
<WorkItem ['001', 2, 'annie', '2008-12-22 19:33', 'planned']: <WorkItem ['001', 3, 'annie', '2008-12-22 19:33', 'planned']:
{'duration': 3600, 'start': 1229970800, 'created': ..., 'creator': 'annie'}> {'duration': 3600, 'start': 1229970800, 'created': ..., 'creator': 'annie'}>
Moving Work Items to Other Tasks
================================
>>> wi10 = wi07.doAction('move', 'john')
>>> wi10
<WorkItem ['001', 4, 'john', '2008-12-22 19:33', 'delegated']:
{'start': 1229970800, 'created': ..., 'source': '0000010', 'creator': 'john'}>
Queries Queries
======= =======
@ -193,7 +202,7 @@ Runs
---- ----
>>> list(tracks.runs) >>> list(tracks.runs)
[2] [2, 3, 4]
>>> list(tracks.finishedRuns) >>> list(tracks.finishedRuns)
[1] [1]
@ -203,8 +212,18 @@ Some Special Cases
Close a run with some delegated items. Close a run with some delegated items.
>>> wi10 = wi09.doAction('finish', 'annie') >>> wi07a = workItems.query(run=2)[-2]
>>> wi11 = wi10.doAction('close', 'john') >>> wi07b = workItems.query(run=2)[-1]
>>> wi07b
<WorkItem ['001', 2, 'john', '2008-12-22 19:33', 'moved']: {'start': 1229970800,
'created': ..., 'target': '0000011', 'creator': 'john'}>
>>> wi07.state >>> wi07c = wi07b.doAction('close', 'john')
>>> wi07a.state
'delegated_x' 'delegated_x'
>>> wi07b.state
'moved_x'
>>> list(tracks.finishedRuns)
[1, 2]

View file

@ -98,6 +98,10 @@ class Track(Persistent):
repr([md[a] for a in self.metadata_attributes]), repr([md[a] for a in self.metadata_attributes]),
repr(self.data)) repr(self.data))
@property
def name(self):
return self.__name__
class TrackingStorage(BTreeContainer): class TrackingStorage(BTreeContainer):