diff --git a/pits_schema.sql b/pits_schema.sql index 8ed251c..5624075 100644 --- a/pits_schema.sql +++ b/pits_schema.sql @@ -14,7 +14,7 @@ CREATE TABLE project ( ); CREATE TABLE task ( - id integer primary key, + id integer primary key, -- TODO When delete, counter go down ==> problem?? Use autoincrement? project_id integer, -- Which project the task belongs to? username text, -- User the task belongs to. name text, -- Task name. @@ -27,6 +27,16 @@ CREATE TABLE task ( updated_at date -- When the task was last updated? ); +-- CREATE TRIGGER insert_task AFTER INSERT ON task +-- BEGIN +-- UPDATE project SET number_of_tasks = (SELECT count(*) FROM task WHERE project_id = new.project_id) WHERE id = new.project_id; +-- END; + +-- CREATE TRIGGER delete_task AFTER DELETE ON task +-- BEGIN +-- UPDATE project SET number_of_tasks = (SELECT count(*) FROM task WHERE project_id = old.project_id) WHERE id = old.project_id; +-- END; + CREATE TABLE note ( id integer primary key, project_id integer, -- Project the note belongs to (0 if belongs to task). diff --git a/project.py b/project.py index dfa6428..4773398 100644 --- a/project.py +++ b/project.py @@ -21,7 +21,7 @@ def handle_project(args, last_action, conn): if args.delete_id: do_something = True delete_project(args.delete_id, conn) - + if args.edit_id: do_something = True edit_project(args, args.edit_id, conn) @@ -94,13 +94,16 @@ def delete_project(project_id, conn): def list_project(active_project_id, conn): logging.info('>> No arguments') - query = "SELECT id, username, name, status, created_at FROM project;" + query = """ + SELECT id, username, name, status, created_at, + (SELECT count(*) FROM task WHERE task.project_id = project.id) + FROM project; + """ cursor = conn.cursor() cursor.execute(query) for row in cursor.fetchall(): - project_id, username, name, status, date = row - nb_task = 0 + project_id, username, name, status, date, nb_task = row current_project = '' if active_project_id and active_project_id == project_id: current_project = '*' - print('{:1} {:2d}: ({:8}) | {} | {} ({} tasks )'.format(current_project, project_id, username, status, name, nb_task)) \ No newline at end of file + print('{:1} {:2d}: ({:8}) | {} | {} ({} tasks)'.format(current_project, project_id, username, status, name, nb_task)) \ No newline at end of file