diff --git a/src/collective/task/browser/guards.py b/src/collective/task/browser/guards.py deleted file mode 100644 index c7e4f9e..0000000 --- a/src/collective/task/browser/guards.py +++ /dev/null @@ -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) diff --git a/src/collective/task/content/task.py b/src/collective/task/content/task.py index d98cd6f..09c2bd0 100644 --- a/src/collective/task/content/task.py +++ b/src/collective/task/content/task.py @@ -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()) diff --git a/src/collective/task/profiles/default/workflows/task_workflow/definition.xml b/src/collective/task/profiles/default/workflows/task_workflow/definition.xml index ebc3a4e..3b5d2cb 100644 --- a/src/collective/task/profiles/default/workflows/task_workflow/definition.xml +++ b/src/collective/task/profiles/default/workflows/task_workflow/definition.xml @@ -127,13 +127,13 @@ Subtask abandoned - here/@@subtasks_abandoned + python: here.subtasks_abandoned() Subtask done - here/@@subtask_done + python: here.subtasks_done()