Work on count nb task (and nb note)
This commit is contained in:
@@ -14,7 +14,7 @@ CREATE TABLE project (
|
|||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE task (
|
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?
|
project_id integer, -- Which project the task belongs to?
|
||||||
username text, -- User the task belongs to.
|
username text, -- User the task belongs to.
|
||||||
name text, -- Task name.
|
name text, -- Task name.
|
||||||
@@ -27,6 +27,16 @@ CREATE TABLE task (
|
|||||||
updated_at date -- When the task was last updated?
|
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 (
|
CREATE TABLE note (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
project_id integer, -- Project the note belongs to (0 if belongs to task).
|
project_id integer, -- Project the note belongs to (0 if belongs to task).
|
||||||
|
|||||||
13
project.py
13
project.py
@@ -21,7 +21,7 @@ def handle_project(args, last_action, conn):
|
|||||||
if args.delete_id:
|
if args.delete_id:
|
||||||
do_something = True
|
do_something = True
|
||||||
delete_project(args.delete_id, conn)
|
delete_project(args.delete_id, conn)
|
||||||
|
|
||||||
if args.edit_id:
|
if args.edit_id:
|
||||||
do_something = True
|
do_something = True
|
||||||
edit_project(args, args.edit_id, conn)
|
edit_project(args, args.edit_id, conn)
|
||||||
@@ -94,13 +94,16 @@ def delete_project(project_id, conn):
|
|||||||
|
|
||||||
def list_project(active_project_id, conn):
|
def list_project(active_project_id, conn):
|
||||||
logging.info('>> No arguments')
|
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 = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
project_id, username, name, status, date = row
|
project_id, username, name, status, date, nb_task = row
|
||||||
nb_task = 0
|
|
||||||
current_project = ''
|
current_project = ''
|
||||||
if active_project_id and active_project_id == project_id: 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))
|
print('{:1} {:2d}: ({:8}) | {} | {} ({} tasks)'.format(current_project, project_id, username, status, name, nb_task))
|
||||||
Reference in New Issue
Block a user