Improve deleting objects
This commit is contained in:
49
note.py
49
note.py
@@ -79,7 +79,7 @@ def create_note(note, active_project_id, active_task_id, conn):
|
||||
|
||||
note_id = cursor.lastrowid
|
||||
|
||||
action_message = "{} (task: {})".format(note.message, active_task_id)
|
||||
action_message = "{} (task {})".format(note.message, active_task_id)
|
||||
record_action(
|
||||
cursor,
|
||||
TypeAction.CREATE,
|
||||
@@ -125,44 +125,33 @@ def edit_note(note, note_id, last_action, conn):
|
||||
def delete_note(note_id, conn):
|
||||
logging.info(">> Remove note")
|
||||
|
||||
query = """
|
||||
DELETE FROM note
|
||||
WHERE id = ?;
|
||||
"""
|
||||
note_name, task_id = get_note_name_task_id(note_id, conn)
|
||||
|
||||
query = "DELETE FROM note WHERE id = ?;"
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (note_id,))
|
||||
|
||||
if cursor.rowcount != 1:
|
||||
logging.error("DELETE FAILED")
|
||||
print("could not find note {}".format(note_id))
|
||||
sys.exit(1)
|
||||
|
||||
record_action(cursor, TypeAction.DELETE, "", note_id=note_id)
|
||||
log_message = "{} (task {})".format(note_name, task_id)
|
||||
|
||||
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
|
||||
record_action(cursor, TypeAction.DELETE, log_message, note_id=note_id)
|
||||
|
||||
print("deleted note {}: {}".format(note_id, log_message))
|
||||
|
||||
|
||||
def list_note(active_project_id, active_task_id, active_note_id, conn):
|
||||
logging.info(">> No arguments")
|
||||
query = (
|
||||
"SELECT id, username, message FROM note WHERE project_id = ? AND task_id = ?;"
|
||||
) # TODO Date & time
|
||||
query = """
|
||||
SELECT id, username, message
|
||||
FROM note
|
||||
WHERE project_id = ?
|
||||
AND task_id = ?;
|
||||
"""
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (active_project_id, active_task_id))
|
||||
@@ -173,3 +162,11 @@ def list_note(active_project_id, active_task_id, active_note_id, conn):
|
||||
"*" if active_note_id == note_id else "", note_id, username, message
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def get_note_name_task_id(note_id, conn):
|
||||
query = "SELECT message, task_id FROM note WHERE id = ?"
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (note_id,))
|
||||
return cursor.fetchone()
|
||||
|
||||
Reference in New Issue
Block a user