From a93b525dcf0f5032ded4bd0e5b261b570c4f45d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 11 Feb 2014 17:44:11 +0100 Subject: [PATCH] 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. --- src/collective/task/browser/guards.py | 33 ------------------- src/collective/task/content/task.py | 11 +++++++ .../workflows/task_workflow/definition.xml | 4 +-- 3 files changed, 13 insertions(+), 35 deletions(-) delete mode 100644 src/collective/task/browser/guards.py 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()