+
+ def done(self):
+ # Refresh, and raise exception if task is already completed/deleted
+ self.refresh(only_fields=['status'])
+
+ if self.completed:
+ raise self.CompletedTask("Cannot complete a completed task")
+ elif self.deleted:
+ raise self.DeletedTask("Deleted task cannot be completed")
+
+ self.warrior.execute_command([self['uuid'], 'done'])
+
+ # Refresh the status again, so that we have updated info stored
+ self.refresh(only_fields=['status'])
+
+ def save(self):
+ args = [self['uuid'], 'modify'] if self['uuid'] else ['add']
+ args.extend(self._get_modified_fields_as_args())
+ self.warrior.execute_command(args)
+ self._modified_fields.clear()
+
+ def add_annotation(self, annotation):
+ args = [self['uuid'], 'annotate', annotation]
+ self.warrior.execute_command(args)
+ self.refresh(only_fields=['annotations'])
+
+ def remove_annotation(self, annotation):
+ if isinstance(annotation, TaskAnnotation):
+ annotation = annotation['description']
+ args = [self['uuid'], 'denotate', annotation]
+ self.warrior.execute_command(args)
+ self.refresh(only_fields=['annotations'])
+
+ def _get_modified_fields_as_args(self):
+ args = []
+ for field in self._modified_fields:
+ args.append('{}:{}'.format(field, self._data[field]))
+ return args
+
+ def refresh(self, only_fields=[]):
+ args = [self['uuid'], 'export']
+ new_data = json.loads(self.warrior.execute_command(args)[0])
+ if only_fields:
+ to_update = dict(
+ [(k, new_data.get(k)) for k in only_fields])
+ self._data.update(to_update)
+ else:
+ self._data = new_data