Skip to content

TaskQuerySet should be sortable by urgency IMO #132

Open
@5balls

Description

@5balls

TaskQuerySet returns an iterable object. It would make sense for me if this object is sorted by urgency or at least sortable by urgency. For this to work there should be __lt__ defined for Task. The wished behaviour can also be accomplished by similar code by extending those classes:

#!/usr/bin/env python3

from tasklib import TaskWarrior
from tasklib.task import Task
from tasklib.task import TaskQuerySet

tw = TaskWarrior(data_location='~/.task')

nexttasks = tw.tasks.pending()

class TaskSortable(Task):
  def __init__(self, task):
    super().__init__(task.backend)
    self._data = task._data
  def __lt__(self,other):
    return self['urgency'] > other['urgency']

class TaskQuerySetSortable(TaskQuerySet):
  def __init__(self, taskqueryset):
    super().__init__(taskqueryset.backend, taskqueryset.filter_obj)
  def _execute(self):
    tasks = []
    for task in super()._execute():
      tasks.append(TaskSortable(task))
    return tasks

if not nexttasks:
  print('No current tasks')
else:
  for task in sorted(TaskQuerySetSortable(nexttasks)):
    print("%s %s %s, " % (task['id'],task['description'],task['urgency']))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions