Compare commits

..

No commits in common. "fb23b5161f5c5e12bc14972f95277ce3d8c5dc1c" and "35aaf17de2a769aae9bc791ebf705d4f255d4294" have entirely different histories.

3 changed files with 6 additions and 28 deletions

View File

@ -2,7 +2,6 @@ import json
from datetime import datetime
from peewee import fn
from .db import db, Task, Category, TaskStatus, SavedSearch
from peewee import Case, Value
def category_lookup(category):
@ -45,15 +44,6 @@ def update_task(
return task
def _get_status_order(status_field):
# CASE statement that maps each status to its position in the order
order_case = Case(
status_field, [(status.value, Value(i)) for i, status in enumerate(TaskStatus)]
)
return order_case
def _parse_sort_string(sort_string, model_class):
"""
Convert sort string like 'field1,-field2' to peewee order_by expressions.
@ -67,13 +57,8 @@ def _parse_sort_string(sort_string, model_class):
is_desc = field.startswith("-")
field_name = field[1:] if is_desc else field
if field == "status":
sort_expressions.append(
_get_status_order(Task.status).desc()
if is_desc
else _get_status_order(Task.status).asc()
)
elif field_name == "due_date":
# special handling for due_date with COALESCE
if field_name == "due_date":
expr = fn.COALESCE(getattr(model_class, field_name), datetime(3000, 12, 31))
sort_expressions.append(expr.desc() if is_desc else expr)
else:

View File

@ -21,10 +21,9 @@ db = SqliteDatabase(
class TaskStatus(Enum):
# order is used for sorting
ZERO = "zero"
WIP = "wip"
BLOCKED = "blocked"
ZERO = "zero"
DONE = "done"

View File

@ -29,7 +29,6 @@ from .utils import (
get_colored_date,
)
DEFAULT_CATEGORY = "main"
COLUMNS = ("ID", "Task", "Status", "Type", "Due", "Category")
column_to_field = {
0: "ID",
@ -232,16 +231,11 @@ class TT(App):
self.refresh_tasks()
def action_add_task(self):
# if filtering on type, status, or category
# the new task should use the selected value
category = self.filters.get("category", DEFAULT_CATEGORY)
status = self.filters.get("status", TaskStatus.ZERO.value).split(",")[0]
type_ = self.filters.get("type", "").split(",")[0]
new_task = add_task(
text="New Task",
type=type_,
status=status,
category=category,
type="",
status=TaskStatus.ZERO.value,
category="main",
)
self.refresh_tasks(restore_cursor=False)
self.move_cursor_to_task(new_task.id)