fix updates

This commit is contained in:
James Turk 2025-01-05 03:21:24 -06:00
parent 426c91ae23
commit b8a86eca16

View File

@ -41,7 +41,6 @@ def update_task(
with db.atomic():
if category := kwargs.pop("category", None):
kwargs["category_id"] = category_lookup(category)
task = Task.get_by_id(task_id)
query = Task.update(kwargs).where(Task.id == task_id)
query.execute()
task = Task.get_by_id(task_id)
@ -108,7 +107,16 @@ def get_categories() -> list[Category]:
def save_view(name: str, *, filters: dict, sort_string: str) -> SavedSearch:
filters_json = json.dumps(filters)
return SavedSearch.create(name=name, filters=filters_json, sort_string=sort_string)
with db.atomic():
if SavedSearch.select(SavedSearch.name == name).exists():
query = SavedSearch.update(
filters=filters_json, sort_string=sort_string
).where(SavedSearch.name == name)
query.execute()
else:
return SavedSearch.create(
name=name, filters=filters_json, sort_string=sort_string
)
def get_saved_view_names() -> list[str]: