diff --git a/dooit/api/todo.py b/dooit/api/todo.py index b8a6da9f..54ad8253 100644 --- a/dooit/api/todo.py +++ b/dooit/api/todo.py @@ -1,4 +1,3 @@ -from functools import cmp_to_key from typing import TYPE_CHECKING, Optional, Union from datetime import datetime, timedelta from typing import List @@ -12,19 +11,6 @@ from dooit.api.workspace import Workspace -def _custom_sort_by_status(x: "Todo", y: "Todo") -> int: - x_values = [not x.pending, x.due or datetime.max, x.order_index] - y_values = [not y.pending, y.due or datetime.max, y.order_index] - - for x_val, y_val in zip(x_values, y_values): - if x_val < y_val: - return -1 - elif x_val > y_val: - return 1 - - return 0 - - class Todo(DooitModel): id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) order_index: Mapped[int] = mapped_column(default=-1) @@ -122,7 +108,11 @@ def sort_siblings(self, field: str): else: items = sorted( self.siblings, - key=cmp_to_key(_custom_sort_by_status), + key=lambda x: ( + not x.pending, + x.due or datetime.max, + x.order_index, + ), ) for index, todo in enumerate(items):