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

fix: todo lister now can list finished task in a better way #1236

Merged
merged 2 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/finished_todos.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Better formatting and ordering of finished todos when `--stati finished` is supplied

**Security:**

* <news item>
23 changes: 18 additions & 5 deletions src/regolith/helpers/l_todohelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,35 @@ def sout(self):
for todo in gather_todos[::-1]:
if todo.get("assigned_by") != rc.assigned_by:
gather_todos.remove(todo)
len_of_started_tasks = 0
len_of_started_tasks, len_of_backburner_tasks, len_of_cancelled_tasks, len_of_finished_tasks = 0, 0, 0, 0
milestones = 0
for todo in gather_todos:
if "milestone: " in todo["description"]:
milestones += 1
elif todo["status"] == "started":
len_of_started_tasks += 1
elif todo["status"] == "backburner":
len_of_backburner_tasks += 1
elif todo["status"] == "cancelled":
len_of_cancelled_tasks += 1
elif todo["status"] == "finished":
len_of_finished_tasks += 1
else:
print(
f" item with invalid status: {todo.get('description')} ({todo.get('running_index')}), "
f"status: {todo.get('status')}"
)
finished_start = len_of_backburner_tasks + len_of_cancelled_tasks
finished_end = finished_start + len_of_finished_tasks
len_of_tasks = len(gather_todos) # - milestones
for todo in gather_todos:
_format_todos(todo, today)
gather_todos[:len_of_tasks] = sorted(
gather_todos[:len_of_tasks],
gather_todos[:] = sorted(
gather_todos[:],
key=lambda k: (k["status"], k["importance"], k["order"], -k.get("duration", 10000)),
)
gather_todos[len_of_started_tasks:len_of_tasks] = sorted(
gather_todos[len_of_started_tasks:len_of_tasks], key=lambda k: (-k["sort_finished"])
gather_todos[finished_start:finished_end] = sorted(
gather_todos[finished_start:finished_end], key=lambda k: (k["sort_finished"])
)
gather_todos[len_of_tasks:] = sorted(
gather_todos[len_of_tasks:], key=lambda k: (k["status"], k["order"], -k.get("duration", 10000))
Expand Down
46 changes: 27 additions & 19 deletions src/regolith/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1896,21 +1896,25 @@ def print_task(task_list, stati, index=True):

Parameters
----------
task_list: list
A list of tasks that will be printed.
stati: list
Filter status of the task
task_list : list
The list of tasks that will be printed.
stati : list
The list of task stati that will be printed
index : bool Optional Default is True
The bool that can suppress printing the preamble of importance, days to due and index

"""
for status in stati:
if f"'status': '{status}'" in str(task_list):
print(f"{status}:")
for task in task_list:
if index:
if index and task.get("status") != "finished":
task["preamble"] = (
f"({task.get('importance')})({task.get('days_to_due')} days): "
f"({task.get('running_index', 0)}) "
)
elif index and task.get("status") == "finished":
task["preamble"] = f"({task.get('end_date')}): " f"({task.get('running_index', 0)}) "
else:
task["preamble"] = ""
if task.get("status") == status:
Expand All @@ -1923,21 +1927,25 @@ def print_task(task_list, stati, index=True):
for note in task.get("notes"):
print(f" - {note}")
print("-" * 76)
print("(importance)(days to due): (Task number) Task (decreasing priority going up)")
if stati == ["finished"]:
print("(Completion Date): (Task number) Task (decreasing priority going up)")
else:
print("(importance)(days to due): (Task number) Task (decreasing priority going up)")
print("-" * 76)
deadline_list = [task for task in task_list if task.get("deadline") and task.get("status") in stati]
deadline_list.sort(key=lambda x: x.get("due_date"), reverse=True)
for task in deadline_list:
print(
f"{task.get('due_date')}({task.get('days_to_due')} days): ({task.get('running_index', 0)}) "
f"{task.get('description').strip()} ({task.get('days_to_due')}|{task.get('importance')}|"
f"{str(task.get('duration'))}|{','.join(task.get('tags', []))}"
f"|{task.get('assigned_by')}|{task.get('uuid')[:6]})"
)
if task.get("notes"):
for note in task.get("notes"):
print(f" - {note}")
print(f"{'-' * 30}\nDeadlines:\n{'-' * 30}")
if stati != ["finished"]:
deadline_list = [task for task in task_list if task.get("deadline") and task.get("status") in stati]
deadline_list.sort(key=lambda x: x.get("due_date"), reverse=True)
for task in deadline_list:
print(
f"{task.get('due_date')}({task.get('days_to_due')} days): ({task.get('running_index', 0)}) "
f"{task.get('description').strip()} ({task.get('days_to_due')}|{task.get('importance')}|"
f"{str(task.get('duration'))}|{','.join(task.get('tags', []))}"
f"|{task.get('assigned_by')}|{task.get('uuid')[:6]})"
)
if task.get("notes"):
for note in task.get("notes"):
print(f" - {note}")
print(f"{'-' * 30}\nDeadlines:\n{'-' * 30}")
return


Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@
" - about 10 minutes\n"
" - don't forget to upload to the website\n"
"finished:\n"
"(2)(-7 days): (3) update the description (-7|2|35.0|tag1,tag2,newtag1,newtag2|sbillinge|test-u)\n"
"(2020-07-07): (3) update the description (-7|2|35.0|tag1,tag2,newtag1,newtag2|sbillinge|test-u)\n"
" - test notes 1\n"
" - test notes 2\n"
" - some new notes\n"
Expand Down
Loading