Cascade deleting

Fix bad note deleting when no ID specified
This commit is contained in:
2018-07-21 16:11:32 +02:00
parent f426b616fd
commit fa25b86a2d
3 changed files with 73 additions and 9 deletions

View File

@@ -4,6 +4,8 @@ import datetime
import logging
import sys
import task
from action import record_action
from action import set_active
from action import TypeAction
@@ -149,12 +151,19 @@ def edit_project(project, project_id, conn):
def delete_project(project_id, conn):
logging.info(">> Remove project")
cursor = conn.cursor()
# Cascade deleting: task
query = "SELECT id FROM task WHERE project_id = ?;"
cursor.execute(query, (project_id,))
for row in cursor.fetchall():
task.delete_task(row[0], project_id, conn)
query = """
DELETE FROM project
WHERE id = ?;
"""
cursor = conn.cursor()
cursor.execute(query, (project_id,))
if cursor.rowcount != 1:
logging.error("DELETE FAILED")
@@ -162,7 +171,22 @@ def delete_project(project_id, conn):
print("deleted project {}: {}".format(project_id, "project_name"))
record_action(cursor, TypeAction.DELETE, "", project_id)
# TODO Cascade deleting
# TODO Good Output
# $ pit p -d
# deleted task 1: efzf (project: 1)
# deleted note 1: fzef (task 3)
# deleted note 2: efz (task 3)
# deleted task 3: efzfzefzef with 2 notes (project: 1)
# deleted note 4: gtrezgze (task 7)
# deleted note 5: fgzegfz (task 7)
# deleted task 7: test with 2 notes (project: 1)
# deleted task 9: a task (project: 1)
# deleted task 10: a task (project: 1)
# deleted note 6: test (task 11)
# deleted note 7: test (task 11)
# deleted note 8: test (task 11)
# deleted task 11: new name with 3 notes (project: 1)
# deleted project 1: test with 6 tasks
def list_project(active_project_id, conn):