Cascade deleting
Fix bad note deleting when no ID specified
This commit is contained in:
18
note.py
18
note.py
@@ -55,7 +55,7 @@ def handle_note(args, last_action, conn):
|
|||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
delete_note(arg_number(args[1]), conn)
|
delete_note(arg_number(args[1]), conn)
|
||||||
else:
|
else:
|
||||||
delete_note(last_action.task_id, conn)
|
delete_note(last_action.note_id, conn)
|
||||||
else:
|
else:
|
||||||
print(f"Invalid note option: {args[0]}")
|
print(f"Invalid note option: {args[0]}")
|
||||||
|
|
||||||
@@ -137,6 +137,22 @@ def delete_note(note_id, conn):
|
|||||||
record_action(cursor, TypeAction.DELETE, "", note_id=note_id)
|
record_action(cursor, TypeAction.DELETE, "", note_id=note_id)
|
||||||
|
|
||||||
print("deleted note {}: {}".format(note_id, "note_name"))
|
print("deleted note {}: {}".format(note_id, "note_name"))
|
||||||
|
# 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_note(active_project_id, active_task_id, active_note_id, conn):
|
def list_note(active_project_id, active_task_id, active_note_id, conn):
|
||||||
|
|||||||
28
project.py
28
project.py
@@ -4,6 +4,8 @@ import datetime
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import task
|
||||||
|
|
||||||
from action import record_action
|
from action import record_action
|
||||||
from action import set_active
|
from action import set_active
|
||||||
from action import TypeAction
|
from action import TypeAction
|
||||||
@@ -149,12 +151,19 @@ def edit_project(project, project_id, conn):
|
|||||||
def delete_project(project_id, conn):
|
def delete_project(project_id, conn):
|
||||||
logging.info(">> Remove project")
|
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 = """
|
query = """
|
||||||
DELETE FROM project
|
DELETE FROM project
|
||||||
WHERE id = ?;
|
WHERE id = ?;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query, (project_id,))
|
cursor.execute(query, (project_id,))
|
||||||
if cursor.rowcount != 1:
|
if cursor.rowcount != 1:
|
||||||
logging.error("DELETE FAILED")
|
logging.error("DELETE FAILED")
|
||||||
@@ -162,7 +171,22 @@ def delete_project(project_id, conn):
|
|||||||
|
|
||||||
print("deleted project {}: {}".format(project_id, "project_name"))
|
print("deleted project {}: {}".format(project_id, "project_name"))
|
||||||
record_action(cursor, TypeAction.DELETE, "", project_id)
|
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):
|
def list_project(active_project_id, conn):
|
||||||
|
|||||||
36
task.py
36
task.py
@@ -12,6 +12,8 @@ from args import arg_number
|
|||||||
|
|
||||||
from utils import get_pits_path
|
from utils import get_pits_path
|
||||||
|
|
||||||
|
import note
|
||||||
|
|
||||||
|
|
||||||
class Task:
|
class Task:
|
||||||
def __init__(self, status=None, priority=None):
|
def __init__(self, status=None, priority=None):
|
||||||
@@ -233,12 +235,19 @@ def moving_task(task_id, old_project_id, project_id, conn):
|
|||||||
def delete_task(task_id, project_id, conn):
|
def delete_task(task_id, project_id, conn):
|
||||||
logging.info(">> Remove task")
|
logging.info(">> Remove task")
|
||||||
|
|
||||||
query = """
|
|
||||||
DELETE FROM task
|
|
||||||
WHERE id = ?;
|
|
||||||
"""
|
|
||||||
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Cascade deleting: note
|
||||||
|
query = "SELECT id FROM note WHERE task_id = ?;"
|
||||||
|
cursor.execute(query, (task_id,))
|
||||||
|
|
||||||
|
for row in cursor.fetchall():
|
||||||
|
note_id = row[0]
|
||||||
|
note.delete_note(note_id, conn)
|
||||||
|
|
||||||
|
# Remove task
|
||||||
|
query = "DELETE FROM task WHERE id = ?;"
|
||||||
|
|
||||||
cursor.execute(query, (task_id,))
|
cursor.execute(query, (task_id,))
|
||||||
if cursor.rowcount != 1:
|
if cursor.rowcount != 1:
|
||||||
logging.error("DELETE FAILED")
|
logging.error("DELETE FAILED")
|
||||||
@@ -247,7 +256,22 @@ def delete_task(task_id, project_id, conn):
|
|||||||
|
|
||||||
print("deleted task {}: {}".format(task_id, "task_name"))
|
print("deleted task {}: {}".format(task_id, "task_name"))
|
||||||
record_action(cursor, TypeAction.DELETE, "", project_id, task_id) # TODO Message
|
record_action(cursor, TypeAction.DELETE, "", project_id, task_id) # TODO Message
|
||||||
# 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_task(active_project_id, active_task_id, conn):
|
def list_task(active_project_id, active_task_id, conn):
|
||||||
|
|||||||
Reference in New Issue
Block a user