From 3713f59e01aaf4e1b86e2e1afdd1de430ea1784e Mon Sep 17 00:00:00 2001 From: kraanzu Date: Thu, 14 Nov 2024 21:47:44 +0530 Subject: [PATCH] try: fix pending sort --- dooit/api/todo.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/dooit/api/todo.py b/dooit/api/todo.py index a1f46fb8..b8a6da9f 100644 --- a/dooit/api/todo.py +++ b/dooit/api/todo.py @@ -13,26 +13,16 @@ def _custom_sort_by_status(x: "Todo", y: "Todo") -> int: - if x.status == y.status: - d1 = x.due or datetime.max - d2 = y.due or datetime.max - if d1 < d2: - return 1 - elif d1 > d2: + 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 - else: - return 0 - - values = {"completed": 0, "pending": 1, "overdue": 2} - s1 = values[x.status] - s2 = values[y.status] - - if s1 < s2: - return 1 - elif s1 > s2: - return -1 - else: - return 0 + elif x_val > y_val: + return 1 + + return 0 class Todo(DooitModel):