WIP Work on action
Very restrictive - use a 'current' table
This commit is contained in:
10
action.py
10
action.py
@@ -13,6 +13,8 @@ class TypeAction(Enum):
|
||||
CREATE = 'created'
|
||||
UPDATE = 'updated'
|
||||
MOVE = 'moved'
|
||||
DELETE = 'deleted'
|
||||
ACTIVE = 'activated'
|
||||
|
||||
class Action:
|
||||
def __init__(self, row):
|
||||
@@ -33,13 +35,15 @@ def handle_action(args, last_action, conn):
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
for row in cursor.fetchall():
|
||||
log_id, project_id, task_id, note_id, username, taction, message, created_at = row
|
||||
_, project_id, task_id, note_id, username, taction, message, created_at = row
|
||||
logging.debug(row)
|
||||
|
||||
formated_date = datetime.strptime(created_at[:26], '%Y-%m-%d %H:%M:%S.%f').strftime('%b %d, %Y %H:%M')
|
||||
|
||||
if taction == 'init':
|
||||
print('{} ({}): {}'.format(formated_date, username, message))
|
||||
elif taction == TypeAction.ACTIVE.value:
|
||||
print('{} ({}): {}'.format(formated_date, username, message))
|
||||
else:
|
||||
object_type = ''
|
||||
id_object = ''
|
||||
@@ -63,12 +67,12 @@ def handle_action(args, last_action, conn):
|
||||
# Jun 13, 2018 01:55 (edelweiss ): updated note 67: (message: Fix anonymize when get a replica with ID [task 30, status:in progress]
|
||||
# Jul 05, 2018 00:40 (budd): moved task 2: from project 1 to project 2
|
||||
|
||||
def create_action(cursor, project_id = '', task_id = '', note_id = '', message = '', action = TypeAction.CREATE):
|
||||
def record_action(cursor, action_type, message, project_id = '', task_id = None, note_id = None):
|
||||
query = """
|
||||
INSERT INTO action (project_id, task_id, note_id, username, action, message, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?);
|
||||
"""
|
||||
cursor.execute(query, (project_id, task_id, note_id, getpass.getuser(), action.value, message, datetime.now(),))
|
||||
cursor.execute(query, (project_id, task_id, note_id, getpass.getuser(), action_type.value, message, datetime.now(),))
|
||||
|
||||
logging.debug('created action')
|
||||
|
||||
|
||||
15
note.py
15
note.py
@@ -7,7 +7,8 @@ import datetime
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import action
|
||||
from action import record_action
|
||||
from action import TypeAction
|
||||
import project
|
||||
|
||||
from args import get_string_arg
|
||||
@@ -31,7 +32,7 @@ def handle_note(args, last_action, conn):
|
||||
sys.exit(1)
|
||||
|
||||
note = Note()
|
||||
note.message = get_string_arg(args[1], 'note message')
|
||||
note.message = get_string_arg(args[1:], 'note message')
|
||||
create_note(note, last_action.project_id, last_action.task_id, conn)
|
||||
elif args[0] == '-e':
|
||||
if len(args) == 1:
|
||||
@@ -73,7 +74,9 @@ def create_note(note, active_project_id, active_task_id, conn):
|
||||
|
||||
note_id = cursor.lastrowid
|
||||
|
||||
action.create_action(cursor, project_id=active_project_id, task_id = active_task_id, note_id=note_id)
|
||||
action_message = '{} (task: {})'.format(note.message, active_task_id)
|
||||
record_action(cursor, TypeAction.CREATE, action_message, active_project_id, active_task_id, note_id)
|
||||
logging.debug(action_message)
|
||||
|
||||
print('created note {}: {} (task {})'.format(note_id, note.message, active_task_id))
|
||||
|
||||
@@ -90,8 +93,10 @@ def edit_note(note, note_id, last_action, conn):
|
||||
print('could not find note {}'.format(note_id))
|
||||
sys.exit(1)
|
||||
|
||||
record_action(cursor, TypeAction.UPDATE, note.message, last_action.project_id,
|
||||
last_action.task_id, last_action.note_id)
|
||||
|
||||
print('updated note {}: (message: {}, task {})'.format(note_id, note.message, last_action.task_id))
|
||||
action.create_action(cursor, project_id=last_action.project_id, task_id=last_action.task_id, note_id=note_id)
|
||||
|
||||
def delete_note(note_id, conn):
|
||||
logging.info('>> Remove note')
|
||||
@@ -108,6 +113,8 @@ def delete_note(note_id, conn):
|
||||
print('could not find note {}'.format(note_id))
|
||||
sys.exit(1)
|
||||
|
||||
record_action(cursor, TypeAction.DELETE, 'delete note')
|
||||
|
||||
print('deleted note {}: {}'.format(note_id, 'note_name'))
|
||||
|
||||
def list_note(active_project_id, active_task_id, active_note_id, conn):
|
||||
|
||||
18
project.py
18
project.py
@@ -7,7 +7,8 @@ import datetime
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import action
|
||||
from action import record_action
|
||||
from action import TypeAction
|
||||
|
||||
from args import get_string_arg
|
||||
from args import arg_number
|
||||
@@ -29,7 +30,7 @@ def handle_project(args, last_action, conn):
|
||||
sys.exit(0)
|
||||
|
||||
if args[0].isdigit():
|
||||
view_project_set_active(int(args[0]), last_action.task_id, conn)
|
||||
view_project_set_active(int(args[0]), last_action, conn)
|
||||
elif args[0] == '-c':
|
||||
if len(args) == 1:
|
||||
print('missing project name')
|
||||
@@ -97,7 +98,8 @@ def create_project(project, conn):
|
||||
cursor.execute(query, (getpass.getuser(), project.name, project.status, datetime.datetime.now(),))
|
||||
project_id = cursor.lastrowid
|
||||
action_message = '{} (status: {})'.format(project.name, project.status)
|
||||
action.create_action(cursor, project_id=project_id, message=action_message)
|
||||
|
||||
record_action(cursor, TypeAction.CREATE, action_message, project_id=project_id)
|
||||
logging.debug(action_message)
|
||||
|
||||
print('created project {}: {} (status: {})'.format(project_id, project.name, project.status))
|
||||
@@ -127,7 +129,7 @@ def edit_project(project, project_id, conn):
|
||||
print('updated project {}: ({})'.format(project_id, log_args))
|
||||
# TODO Bad output
|
||||
|
||||
action.create_action(cursor, project_id, message = 'update ' + str(update_args))
|
||||
record_action(cursor, TypeAction.UPDATE, 'update ' + str(update_args), project_id)
|
||||
|
||||
def delete_project(project_id, conn):
|
||||
logging.info('>> Remove project')
|
||||
@@ -144,6 +146,7 @@ def delete_project(project_id, conn):
|
||||
print('could not find project {}'.format(project_id))
|
||||
|
||||
print('deleted project {}: {}'.format(project_id, 'project_name'))
|
||||
record_action(cursor, TypeAction.DELETE, 'delete', None) # TODO Message
|
||||
# TODO Cascade deleting
|
||||
|
||||
def list_project(active_project_id, conn):
|
||||
@@ -162,7 +165,7 @@ def list_project(active_project_id, conn):
|
||||
print('{:1} {:2d}: ({:8}) | {} | {} ({} tasks)'.format('*' if active_project_id == project_id else '',
|
||||
project_id, username, status, name, nb_task))
|
||||
|
||||
def view_project_set_active(project_id, act_task_id, conn):
|
||||
def view_project_set_active(project_id, last_action, conn):
|
||||
# FIXME duplicate with list_project
|
||||
query = """
|
||||
SELECT id, username, name, status,
|
||||
@@ -190,8 +193,9 @@ def view_project_set_active(project_id, act_task_id, conn):
|
||||
logging.debug('Task row: {}'.format(row))
|
||||
task_id, username, name, status, priority, date, time, nb_note = row
|
||||
message = date + time + name
|
||||
print(' {} {:d}: ({}) [{}] [{}] {} ({} tasks)'.format('*' if act_task_id == row[0] else ' ',
|
||||
print(' {} {:d}: ({}) [{}] [{}] {} ({} tasks)'.format('*' if last_action.task_id == row[0] else ' ',
|
||||
task_id, username, status, priority, message, nb_note))
|
||||
action.create_action(cursor, project_id=project_id)
|
||||
record_action(cursor, TypeAction.ACTIVE, 'set active project ' + str(project_id),
|
||||
project_id, last_action.task_id, last_action.note_id)
|
||||
|
||||
# TODO Add a -v option to see notes?
|
||||
29
task.py
29
task.py
@@ -7,7 +7,8 @@ import datetime
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import action
|
||||
from action import record_action
|
||||
from action import TypeAction
|
||||
from args import get_string_arg
|
||||
from args import arg_number
|
||||
|
||||
@@ -28,7 +29,7 @@ def handle_task(args, last_action, conn):
|
||||
sys.exit(0)
|
||||
|
||||
if args[0].isdigit():
|
||||
view_task_set_active(arg_number(args[0]), last_action.note_id, last_action.project_id, conn)
|
||||
view_task_set_active(arg_number(args[0]), last_action, conn)
|
||||
elif args[0] == '-c':
|
||||
if len(args) == 1:
|
||||
print('missing task name')
|
||||
@@ -49,7 +50,7 @@ def handle_task(args, last_action, conn):
|
||||
task_id = int(args[1])
|
||||
parse_task_args(task, args[2:])
|
||||
else:
|
||||
task_id = last_action.task_id
|
||||
task_id = last_action.task_id # FIXME If no active tast - use incremental args_i
|
||||
parse_task_args(task, args[1:])
|
||||
logging.debug('Task: ({}) {}'.format(task_id, task))
|
||||
|
||||
@@ -58,9 +59,9 @@ def handle_task(args, last_action, conn):
|
||||
elif args[0] == '-d':
|
||||
# FIXME Duplicate code
|
||||
if len(args) > 1:
|
||||
delete_task(arg_number(args[1]), conn)
|
||||
delete_task(arg_number(args[1]),last_action.project_id, conn)
|
||||
else:
|
||||
delete_task(last_action.task_id, conn)
|
||||
delete_task(last_action.task_id,last_action.project_id, conn)
|
||||
elif args[0] == '-m':
|
||||
# Try another logic
|
||||
args_i = 1
|
||||
@@ -88,7 +89,7 @@ def handle_task(args, last_action, conn):
|
||||
|
||||
moving_task(task_id, last_action.project_id, arg_number(args[args_i]), conn)
|
||||
else:
|
||||
print(f'Invalid project option: {args[0]}')
|
||||
print(f'Invalid task option: {args[0]}')
|
||||
|
||||
# TODO Cascade deleting
|
||||
|
||||
@@ -148,7 +149,7 @@ def create_task(task, project_id, conn):
|
||||
|
||||
action_message = '{} ({}, project: {})'.format(task.name, log_args, project_id)
|
||||
|
||||
action.create_action(cursor, project_id=project_id, task_id=task_id, message=action_message)
|
||||
record_action(cursor, TypeAction.CREATE, action_message, project_id, task_id)
|
||||
print('created task {}: {}'.format(task_id, action_message))
|
||||
|
||||
def edit_task(task, task_id, project_id, conn):
|
||||
@@ -178,7 +179,7 @@ def edit_task(task, task_id, project_id, conn):
|
||||
|
||||
# TODO Retrieve project id ?
|
||||
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)
|
||||
record_action(cursor, TypeAction.UPDATE, action_message, project_id, task_id)
|
||||
|
||||
def moving_task(task_id, old_project_id, project_id, conn):
|
||||
logging.info('>> Moving task')
|
||||
@@ -195,9 +196,9 @@ def moving_task(task_id, old_project_id, project_id, conn):
|
||||
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
|
||||
record_action(cursor, TypeAction.MOVE, '', project_id=project_id, task_id=task_id) # TODO Message
|
||||
|
||||
def delete_task(task_id, conn):
|
||||
def delete_task(task_id, project_id, conn):
|
||||
logging.info('>> Remove task')
|
||||
|
||||
query = """
|
||||
@@ -213,6 +214,7 @@ def delete_task(task_id, conn):
|
||||
sys.exit(1)
|
||||
|
||||
print('deleted task {}: {}'.format(task_id, 'task_name'))
|
||||
record_action(cursor, TypeAction.DELETE, '', project_id, None) # TODO Message
|
||||
|
||||
def list_task(active_project_id, active_task_id, conn):
|
||||
logging.info('>> No arguments')
|
||||
@@ -234,7 +236,7 @@ def list_task(active_project_id, active_task_id, conn):
|
||||
# 2: (budd) |open| |normal| test (0 notes)
|
||||
# * 3: (budd) |open| |normal| Dec 31, 2018 tet (0 notes)
|
||||
|
||||
def view_task_set_active(task_id, act_note_id, project_id, conn):
|
||||
def view_task_set_active(task_id, last_action, conn):
|
||||
# FIXME duplicate with list_task / view_project_set_active
|
||||
query = """
|
||||
SELECT id, username, status, priority, name,
|
||||
@@ -259,9 +261,10 @@ def view_task_set_active(task_id, act_note_id, project_id, conn):
|
||||
for row in cursor.fetchall():
|
||||
logging.debug('Note row: {}'.format(row))
|
||||
note_id, username, message = row
|
||||
print(' {} {:d}: ({}) {}'.format('*' if act_note_id == row[0] else ' ',
|
||||
print(' {} {:d}: ({}) {}'.format('*' if last_action.note_id == row[0] else ' ',
|
||||
note_id, username, message))
|
||||
action.create_action(cursor, project_id=project_id, task_id=task_id)
|
||||
record_action(cursor, TypeAction.ACTIVE, 'set active task ' + str(task_id),
|
||||
last_action.project_id, last_action.task_id, last_action.note_id)
|
||||
|
||||
# $ pit t 11
|
||||
# * 11: (budd) a task (project: 1, status: in progress, priority: high, date: Apr 26, 2018, time: 5:00, 2 notes)
|
||||
|
||||
Reference in New Issue
Block a user