aboutsummaryrefslogtreecommitdiff
path: root/todo/service/tasks.py
diff options
context:
space:
mode:
authorJoris2020-06-14 12:01:36 +0200
committerJoris2020-06-14 12:01:36 +0200
commit4e923888896798da6db7b50c75ee31fcc5119e16 (patch)
tree5674e22f97a6b3567ce2a8126d5aedb75d774b11 /todo/service/tasks.py
parentc34efadf89c590d367faa0c9128fba6e92e5f3ed (diff)
downloadtodo-4e923888896798da6db7b50c75ee31fcc5119e16.tar.gz
todo-4e923888896798da6db7b50c75ee31fcc5119e16.tar.bz2
todo-4e923888896798da6db7b50c75ee31fcc5119e16.zip
Improve tag update
Diffstat (limited to 'todo/service/tasks.py')
-rw-r--r--todo/service/tasks.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/todo/service/tasks.py b/todo/service/tasks.py
index 2cebf00..c01ab8a 100644
--- a/todo/service/tasks.py
+++ b/todo/service/tasks.py
@@ -15,15 +15,19 @@ def create(cursor, status: Status, task_form: ValidTaskForm) -> Task:
todo.database.commit()
return task
-def update(cursor, task: Task, task_form: ValidTaskForm) -> Task:
- todo.db.task_tags.delete(cursor, [task.id])
+def update(cursor, task: Task, tags: List[int], task_form: ValidTaskForm) -> Task:
+ old_tags = [t for t in tags if t not in task_form.tags]
+ todo.db.task_tags.delete_from_tags(cursor, task.id, old_tags)
+
+ new_tags = [t for t in task_form.tags if t not in tags]
+ todo.db.task_tags.insert_many(cursor, task.id, new_tags)
+
updated_task = todo.db.tasks.update(cursor, task, task_form)
- todo.db.task_tags.insert_many(cursor, task.id, task_form.tags)
todo.database.commit()
return updated_task
def delete(cursor, task_ids: List[int]):
- todo.db.task_tags.delete(cursor, task_ids)
+ todo.db.task_tags.delete_from_tasks(cursor, task_ids)
todo.db.tasks.delete(cursor, task_ids)
todo.database.commit()