change guards to use python expressions (#3791)
Too many hours spent debugging the reason why the here/@@subtasks_abandoned task expression that was there wouldn't work.
This commit is contained in:
parent
f50dfe6a0d
commit
a93b525dcf
|
@ -1,33 +0,0 @@
|
|||
from five import grok
|
||||
|
||||
from plone import api
|
||||
|
||||
from collective.task.content.task import ITask
|
||||
|
||||
|
||||
class BaseSubtaskGuard(grok.View):
|
||||
"""Base class for 'subtask' guards views"""
|
||||
grok.context(ITask)
|
||||
grok.baseclass()
|
||||
grok.require("zope2.View")
|
||||
|
||||
def update(self):
|
||||
"""Create subtasks states list"""
|
||||
subtasks = self.context.listFolderContents()
|
||||
self.subtasks_states = [api.content.get_state(subtask) for subtask in subtasks]
|
||||
|
||||
|
||||
class SubtaskDoneGuard(BaseSubtaskGuard):
|
||||
"""Returns True if the subtask is done"""
|
||||
grok.name("subtask_done")
|
||||
|
||||
def render(self):
|
||||
return 'done' in self.subtasks_states
|
||||
|
||||
|
||||
class SubtasksAbandonedGuard(BaseSubtaskGuard):
|
||||
"""Returns True is the subtask is abandoned"""
|
||||
grok.name("subtasks_abandoned")
|
||||
|
||||
def render(self):
|
||||
return set(['abandoned']) == set(self.subtasks_states)
|
|
@ -1,6 +1,7 @@
|
|||
from zope.interface import implements
|
||||
|
||||
from plone.dexterity.content import Container
|
||||
from plone import api
|
||||
|
||||
from collective.task.interfaces import IBaseTask, IDeadline
|
||||
|
||||
|
@ -17,3 +18,13 @@ class Task(Container):
|
|||
meta_type = 'task'
|
||||
# disable local roles inheritance
|
||||
__ac_local_roles_block__ = True
|
||||
|
||||
def get_subtask_states(self):
|
||||
subtasks = self.listFolderContents()
|
||||
return [api.content.get_state(subtask) for subtask in subtasks]
|
||||
|
||||
def subtasks_abandoned(self):
|
||||
return set(['abandoned']) == set(self.get_subtask_states())
|
||||
|
||||
def subtasks_done(self):
|
||||
return set(['done']) == set(self.get_subtask_states())
|
||||
|
|
|
@ -127,13 +127,13 @@
|
|||
<transition transition_id="subtask-abandoned" title="Subtask abandoned" new_state="todo" trigger="USER" before_script="" after_script="">
|
||||
<action url="" category="workflow" icon="" i18n:translate="">Subtask abandoned</action>
|
||||
<guard>
|
||||
<guard-expression>here/@@subtasks_abandoned</guard-expression>
|
||||
<guard-expression>python: here.subtasks_abandoned()</guard-expression>
|
||||
</guard>
|
||||
</transition>
|
||||
<transition transition_id="subtask-done" title="Subtask done" new_state="done" trigger="USER" before_script="" after_script="">
|
||||
<action url="" category="workflow" icon="" i18n:translate="">Subtask done</action>
|
||||
<guard>
|
||||
<guard-expression>here/@@subtask_done</guard-expression>
|
||||
<guard-expression>python: here.subtasks_done()</guard-expression>
|
||||
</guard>
|
||||
</transition>
|
||||
<transition transition_id="take-responsibility" title="Take responsibility" new_state="in-progress" trigger="USER" before_script="" after_script="">
|
||||
|
|
Reference in New Issue