From 15c5d693afb61c72f6a6984c25dacb8610b2d9a8 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 8 Aug 2015 20:06:03 +0200 Subject: [PATCH 1/1] Task: Move TW-specific completion logic into TW backend --- tasklib/backends.py | 8 ++++++++ tasklib/task.py | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tasklib/backends.py b/tasklib/backends.py index c99d63f..e7b9a74 100644 --- a/tasklib/backends.py +++ b/tasklib/backends.py @@ -213,3 +213,11 @@ class TaskWarrior(object): def stop_task(self, task): self.execute_command([task['uuid'], 'stop']) + + def complete_task(self, task): + # Older versions of TW do not stop active task at completion + if self.version < VERSION_2_4_0 and task.active: + task.stop() + + self.execute_command([task['uuid'], 'done']) + diff --git a/tasklib/task.py b/tasklib/task.py index b7bba4b..3f53511 100644 --- a/tasklib/task.py +++ b/tasklib/task.py @@ -637,11 +637,7 @@ class Task(TaskResource): elif self.deleted: raise Task.DeletedTask("Deleted task cannot be completed") - # Older versions of TW do not stop active task at completion - if self.warrior.version < VERSION_2_4_0 and self.active: - self.stop() - - self.warrior.execute_command([self['uuid'], 'done']) + self.backend.complete_task(self) # Refresh the status again, so that we have updated info stored self.refresh(only_fields=['status', 'start', 'end']) -- 2.39.5