From: Tomas Babej Date: Sat, 8 Aug 2015 18:06:03 +0000 (+0200) Subject: Task: Move TW-specific completion logic into TW backend X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/15c5d693afb61c72f6a6984c25dacb8610b2d9a8?ds=inline Task: Move TW-specific completion logic into TW backend --- 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'])