Move task
This commit is contained in:
56
task.py
56
task.py
@@ -9,6 +9,7 @@ import sys
|
|||||||
|
|
||||||
import action
|
import action
|
||||||
from args import get_string_arg
|
from args import get_string_arg
|
||||||
|
from args import arg_number
|
||||||
|
|
||||||
class Task:
|
class Task:
|
||||||
def __init__(self, status = None, priority = None):
|
def __init__(self, status = None, priority = None):
|
||||||
@@ -54,9 +55,43 @@ def handle_task(args, last_action, conn):
|
|||||||
|
|
||||||
edit_task(task, task_id, last_action.project_id, conn)
|
edit_task(task, task_id, last_action.project_id, conn)
|
||||||
# TODO To set as active project, us a -a option?
|
# TODO To set as active project, us a -a option?
|
||||||
|
elif args[0] == '-d':
|
||||||
|
# FIXME Duplicate code
|
||||||
|
if len(args) > 1:
|
||||||
|
delete_task(arg_number(args[1]), conn)
|
||||||
|
else:
|
||||||
|
delete_task(last_action.task_id, conn)
|
||||||
|
elif args[0] == '-m':
|
||||||
|
# Try another logic
|
||||||
|
args_i = 1
|
||||||
|
if len(args) < 3:
|
||||||
|
print('missing project number')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
task_id = last_action.task_id
|
||||||
|
|
||||||
|
# Task id
|
||||||
|
if args[args_i].isdigit():
|
||||||
|
task_id = arg_number(args[args_i])
|
||||||
|
args_i += 1
|
||||||
|
|
||||||
|
if not task_id:
|
||||||
|
print('No active task to move.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Project option - if not fail
|
||||||
|
if args[args_i] != '-p':
|
||||||
|
print('missing project number')
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
args_i += 1
|
||||||
|
|
||||||
|
moving_task(task_id, last_action.project_id, arg_number(args[args_i]), conn)
|
||||||
else:
|
else:
|
||||||
print(f'Invalid project option: {args[0]}')
|
print(f'Invalid project option: {args[0]}')
|
||||||
|
|
||||||
|
# TODO Cascade deleting
|
||||||
|
|
||||||
def parse_task_args(task, args):
|
def parse_task_args(task, args):
|
||||||
if not args:
|
if not args:
|
||||||
return
|
return
|
||||||
@@ -145,8 +180,22 @@ def edit_task(task, task_id, project_id, conn):
|
|||||||
logging.debug('UPDATE TASK - ACTION MESSAGE : ' + action_message)
|
logging.debug('UPDATE TASK - ACTION MESSAGE : ' + action_message)
|
||||||
action.create_action(cursor, project_id=project_id, task_id=task_id, action=action.TypeAction.UPDATE, message = action_message)
|
action.create_action(cursor, project_id=project_id, task_id=task_id, action=action.TypeAction.UPDATE, message = action_message)
|
||||||
|
|
||||||
def moving_task(args):
|
def moving_task(task_id, old_project_id, project_id, conn):
|
||||||
print('moving')
|
logging.info('>> Moving task')
|
||||||
|
|
||||||
|
query = """
|
||||||
|
UPDATE task SET project_id = ? WHERE id = ?;
|
||||||
|
"""
|
||||||
|
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(query, (project_id, task_id,))
|
||||||
|
|
||||||
|
if cursor.rowcount != 1:
|
||||||
|
print('Problem occur when moving task...')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print('moved task {}: from project {} to project {}'.format(task_id, old_project_id, project_id))
|
||||||
|
action.create_action(cursor, project_id=project_id, task_id=task_id) # TODO Message
|
||||||
|
|
||||||
def delete_task(task_id, conn):
|
def delete_task(task_id, conn):
|
||||||
logging.info('>> Remove task')
|
logging.info('>> Remove task')
|
||||||
@@ -160,6 +209,9 @@ def delete_task(task_id, conn):
|
|||||||
cursor.execute(query, (task_id,))
|
cursor.execute(query, (task_id,))
|
||||||
if cursor.rowcount != 1:
|
if cursor.rowcount != 1:
|
||||||
logging.error('DELETE FAILED')
|
logging.error('DELETE FAILED')
|
||||||
|
print('could not find task {}'.format(task_id))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
print('deleted task {}: {}'.format(task_id, 'task_name'))
|
print('deleted task {}: {}'.format(task_id, 'task_name'))
|
||||||
|
|
||||||
def list_task(active_project_id, active_task_id, conn):
|
def list_task(active_project_id, active_task_id, conn):
|
||||||
|
|||||||
Reference in New Issue
Block a user