Compare commits
No commits in common. "fb23b5161f5c5e12bc14972f95277ce3d8c5dc1c" and "35aaf17de2a769aae9bc791ebf705d4f255d4294" have entirely different histories.
fb23b5161f
...
35aaf17de2
@ -2,7 +2,6 @@ import json
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from peewee import fn
|
from peewee import fn
|
||||||
from .db import db, Task, Category, TaskStatus, SavedSearch
|
from .db import db, Task, Category, TaskStatus, SavedSearch
|
||||||
from peewee import Case, Value
|
|
||||||
|
|
||||||
|
|
||||||
def category_lookup(category):
|
def category_lookup(category):
|
||||||
@ -45,15 +44,6 @@ def update_task(
|
|||||||
return 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):
|
def _parse_sort_string(sort_string, model_class):
|
||||||
"""
|
"""
|
||||||
Convert sort string like 'field1,-field2' to peewee order_by expressions.
|
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("-")
|
is_desc = field.startswith("-")
|
||||||
field_name = field[1:] if is_desc else field
|
field_name = field[1:] if is_desc else field
|
||||||
|
|
||||||
if field == "status":
|
# special handling for due_date with COALESCE
|
||||||
sort_expressions.append(
|
if field_name == "due_date":
|
||||||
_get_status_order(Task.status).desc()
|
|
||||||
if is_desc
|
|
||||||
else _get_status_order(Task.status).asc()
|
|
||||||
)
|
|
||||||
elif field_name == "due_date":
|
|
||||||
expr = fn.COALESCE(getattr(model_class, field_name), datetime(3000, 12, 31))
|
expr = fn.COALESCE(getattr(model_class, field_name), datetime(3000, 12, 31))
|
||||||
sort_expressions.append(expr.desc() if is_desc else expr)
|
sort_expressions.append(expr.desc() if is_desc else expr)
|
||||||
else:
|
else:
|
||||||
|
@ -21,10 +21,9 @@ db = SqliteDatabase(
|
|||||||
|
|
||||||
|
|
||||||
class TaskStatus(Enum):
|
class TaskStatus(Enum):
|
||||||
# order is used for sorting
|
ZERO = "zero"
|
||||||
WIP = "wip"
|
WIP = "wip"
|
||||||
BLOCKED = "blocked"
|
BLOCKED = "blocked"
|
||||||
ZERO = "zero"
|
|
||||||
DONE = "done"
|
DONE = "done"
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ from .utils import (
|
|||||||
get_colored_date,
|
get_colored_date,
|
||||||
)
|
)
|
||||||
|
|
||||||
DEFAULT_CATEGORY = "main"
|
|
||||||
COLUMNS = ("ID", "Task", "Status", "Type", "Due", "Category")
|
COLUMNS = ("ID", "Task", "Status", "Type", "Due", "Category")
|
||||||
column_to_field = {
|
column_to_field = {
|
||||||
0: "ID",
|
0: "ID",
|
||||||
@ -232,16 +231,11 @@ class TT(App):
|
|||||||
self.refresh_tasks()
|
self.refresh_tasks()
|
||||||
|
|
||||||
def action_add_task(self):
|
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(
|
new_task = add_task(
|
||||||
text="New Task",
|
text="New Task",
|
||||||
type=type_,
|
type="",
|
||||||
status=status,
|
status=TaskStatus.ZERO.value,
|
||||||
category=category,
|
category="main",
|
||||||
)
|
)
|
||||||
self.refresh_tasks(restore_cursor=False)
|
self.refresh_tasks(restore_cursor=False)
|
||||||
self.move_cursor_to_task(new_task.id)
|
self.move_cursor_to_task(new_task.id)
|
||||||
|
Loading…
Reference in New Issue
Block a user