diff --git a/src/tt/controller.py b/src/tt/controller.py index 535e6ef..cd3c004 100644 --- a/src/tt/controller.py +++ b/src/tt/controller.py @@ -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]: