Improve how to retrieve & handle actions
This commit is contained in:
18
action.py
18
action.py
@@ -7,6 +7,18 @@ import datetime
|
|||||||
import logging
|
import logging
|
||||||
import action
|
import action
|
||||||
|
|
||||||
|
class Action:
|
||||||
|
def __init__(self, row):
|
||||||
|
if not row:
|
||||||
|
logging.debug('Action - empty row')
|
||||||
|
raise Exception('No action found - database need to be initialized.')
|
||||||
|
else:
|
||||||
|
logging.debug('Action - fill fields')
|
||||||
|
self.project_id, self.task_id, self.note_id = row
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.__dict__)
|
||||||
|
|
||||||
def create_action(cursor, project_id = '', task_id = '', note_id = '', message = ''):
|
def create_action(cursor, project_id = '', task_id = '', note_id = '', message = ''):
|
||||||
query = """
|
query = """
|
||||||
INSERT INTO action (project_id, task_id, note_id, username, message, created_at)
|
INSERT INTO action (project_id, task_id, note_id, username, message, created_at)
|
||||||
@@ -21,11 +33,9 @@ def read_last_action(conn):
|
|||||||
logging.info('> last_action')
|
logging.info('> last_action')
|
||||||
# query = 'SELECT * FROM action WHERE id = (SELECT MAX(id) FROM action'
|
# query = 'SELECT * FROM action WHERE id = (SELECT MAX(id) FROM action'
|
||||||
# query = 'SELECT project_id, task_id, note_id FROM action'
|
# query = 'SELECT project_id, task_id, note_id FROM action'
|
||||||
query = 'SELECT project_id, task_id, note_id FROM action ORDER BY created_at DESC LIMIT 1;'
|
query = 'SELECT project_id, task_id, note_id FROM action ORDER BY id DESC LIMIT 1;'
|
||||||
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
logging.debug('DEEEEEEEEBU')
|
last_action = Action(cursor.fetchone())
|
||||||
last_action = cursor.fetchone()
|
|
||||||
logging.debug(last_action)
|
|
||||||
return last_action
|
return last_action
|
||||||
10
project.py
10
project.py
@@ -27,10 +27,7 @@ def handle_project(args, last_action, conn):
|
|||||||
edit_project(args, args.edit_id, conn)
|
edit_project(args, args.edit_id, conn)
|
||||||
|
|
||||||
if not do_something:
|
if not do_something:
|
||||||
active_project_id = None
|
list_project(last_action.project_id, conn)
|
||||||
if last_action:
|
|
||||||
active_project_id = last_action[0]
|
|
||||||
list_project(active_project_id, conn)
|
|
||||||
|
|
||||||
def create_project(args, conn):
|
def create_project(args, conn):
|
||||||
# TODO Project is same name is forbidden
|
# TODO Project is same name is forbidden
|
||||||
@@ -104,6 +101,5 @@ def list_project(active_project_id, conn):
|
|||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
project_id, username, name, status, date, nb_task = row
|
project_id, username, name, status, date, nb_task = row
|
||||||
current_project = ''
|
print('{:1} {:2d}: ({:8}) | {} | {} ({} tasks)'.format('*' if active_project_id == project_id else '',
|
||||||
if active_project_id and active_project_id == project_id: current_project = '*'
|
project_id, username, status, name, nb_task))
|
||||||
print('{:1} {:2d}: ({:8}) | {} | {} ({} tasks)'.format(current_project, project_id, username, status, name, nb_task))
|
|
||||||
26
task.py
26
task.py
@@ -12,21 +12,13 @@ def handle_task(args, last_action, conn):
|
|||||||
logging.info('> handle task')
|
logging.info('> handle task')
|
||||||
logging.debug('args: ' + str(args))
|
logging.debug('args: ' + str(args))
|
||||||
|
|
||||||
active_project_id = None
|
logging.debug('Last action: {}'.format(last_action))
|
||||||
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))
|
|
||||||
|
|
||||||
do_something = False
|
do_something = False
|
||||||
|
|
||||||
if args.create_name:
|
if args.create_name:
|
||||||
do_something = True
|
do_something = True
|
||||||
create_task(args, active_project_id, conn)
|
create_task(args, last_action.project_id, conn)
|
||||||
|
|
||||||
if args.delete_id:
|
if args.delete_id:
|
||||||
do_something = True
|
do_something = True
|
||||||
@@ -41,13 +33,15 @@ def handle_task(args, last_action, conn):
|
|||||||
edit_task(args, args.edit_id, conn)
|
edit_task(args, args.edit_id, conn)
|
||||||
|
|
||||||
if not do_something:
|
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):
|
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')
|
logging.info('>> Create task')
|
||||||
|
|
||||||
query = """
|
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 (?, ?, ?, ?, ?, ?, ?, ?);
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -58,7 +52,8 @@ def create_task(args, active_project_id, conn):
|
|||||||
time = ''
|
time = ''
|
||||||
|
|
||||||
cursor = conn.cursor()
|
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
|
task_id = cursor.lastrowid
|
||||||
|
|
||||||
@@ -118,9 +113,8 @@ def list_task(active_project_id, active_task_id, conn):
|
|||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
nb_note = 0
|
nb_note = 0
|
||||||
task_id, username, status, priority, name = row
|
task_id, username, status, priority, name = row
|
||||||
current_task = ''
|
print('{:1} {:2d}: ({:8}) | {} | {} | {} ({} tasks )'.format('*' if active_task_id == task_id else '', task_id,
|
||||||
if active_task_id and active_task_id == task_id: current_task = '*'
|
username, status, priority, name, nb_note))
|
||||||
print('{:1} {:2d}: ({:8}) | {} | {} | {} ({} tasks )'.format(current_task, task_id, username, status, priority, name, nb_note))
|
|
||||||
|
|
||||||
# 2: (budd) |open| |normal| test (0 notes)
|
# 2: (budd) |open| |normal| test (0 notes)
|
||||||
# * 3: (budd) |open| |normal| Dec 31, 2018 tet (0 notes)
|
# * 3: (budd) |open| |normal| Dec 31, 2018 tet (0 notes)
|
||||||
Reference in New Issue
Block a user