Work on count nb task (and nb note)

This commit is contained in:
2018-07-04 02:30:40 +02:00
parent 17d42cc584
commit 7726f53013
2 changed files with 19 additions and 6 deletions

View File

@@ -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).

View File

@@ -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))