Improve how to retrieve & handle actions
This commit is contained in:
28
task.py
28
task.py
@@ -12,21 +12,13 @@ def handle_task(args, last_action, conn):
|
||||
logging.info('> handle task')
|
||||
logging.debug('args: ' + str(args))
|
||||
|
||||
active_project_id = None
|
||||
if last_action:
|
||||
active_project_id = last_action[0]
|
||||
|
||||
active_task_id = None
|
||||
if last_action:
|
||||
active_task_id = last_action[1]
|
||||
|
||||
logging.debug('Last action, project id: {} | task id: {}'.format(active_project_id, active_task_id))
|
||||
logging.debug('Last action: {}'.format(last_action))
|
||||
|
||||
do_something = False
|
||||
|
||||
if args.create_name:
|
||||
do_something = True
|
||||
create_task(args, active_project_id, conn)
|
||||
create_task(args, last_action.project_id, conn)
|
||||
|
||||
if args.delete_id:
|
||||
do_something = True
|
||||
@@ -35,19 +27,21 @@ def handle_task(args, last_action, conn):
|
||||
if args.moving_id:
|
||||
do_something = True
|
||||
moving_task(args)
|
||||
|
||||
|
||||
if args.edit_id:
|
||||
do_something = True
|
||||
edit_task(args, args.edit_id, conn)
|
||||
|
||||
if not do_something:
|
||||
list_task(active_project_id, active_task_id, conn)
|
||||
list_task(last_action.project_id, last_action.task_id, conn)
|
||||
|
||||
def create_task(args, active_project_id, conn):
|
||||
# TODO Don't create task if no project (nothing selected?) ==> foreign key is not a solution: there is no project ID :)
|
||||
logging.info('>> Create task')
|
||||
|
||||
query = """
|
||||
INSERT INTO task (project_id, username, name, status, priority, date, time, created_at)
|
||||
INSERT INTO
|
||||
task (project_id, username, name, status, priority, date, time, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
||||
"""
|
||||
|
||||
@@ -58,7 +52,8 @@ def create_task(args, active_project_id, conn):
|
||||
time = ''
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (active_project_id, getpass.getuser(), args.create_name, status, priority, date, time, datetime.datetime.now(),))
|
||||
cursor.execute(query, (active_project_id, getpass.getuser(), args.create_name, status, priority, date, time,
|
||||
datetime.datetime.now(),))
|
||||
|
||||
task_id = cursor.lastrowid
|
||||
|
||||
@@ -118,9 +113,8 @@ def list_task(active_project_id, active_task_id, conn):
|
||||
for row in cursor.fetchall():
|
||||
nb_note = 0
|
||||
task_id, username, status, priority, name = row
|
||||
current_task = ''
|
||||
if active_task_id and active_task_id == task_id: current_task = '*'
|
||||
print('{:1} {:2d}: ({:8}) | {} | {} | {} ({} tasks )'.format(current_task, task_id, username, status, priority, name, nb_note))
|
||||
print('{:1} {:2d}: ({:8}) | {} | {} | {} ({} tasks )'.format('*' if active_task_id == task_id else '', task_id,
|
||||
username, status, priority, name, nb_note))
|
||||
|
||||
# 2: (budd) |open| |normal| test (0 notes)
|
||||
# * 3: (budd) |open| |normal| Dec 31, 2018 tet (0 notes)
|
||||
Reference in New Issue
Block a user