Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TaskQuerySet should be sortable by urgency IMO #132

Open
5balls opened this issue Oct 4, 2024 · 0 comments
Open

TaskQuerySet should be sortable by urgency IMO #132

5balls opened this issue Oct 4, 2024 · 0 comments

Comments

@5balls
Copy link

5balls commented Oct 4, 2024

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']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant