From e4217316085b9cb1dbf9d9dbfaef288ade0cc5b1 Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Thu, 5 Jul 2018 01:01:18 +0200 Subject: [PATCH] WIP on action/log --- action.py | 42 ++++++++++++++++++++++++++++++++++-------- pits_schema.sql | 1 + project.py | 5 +++-- task.py | 12 ++++++++++-- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/action.py b/action.py index a061684..f8148d1 100644 --- a/action.py +++ b/action.py @@ -5,7 +5,13 @@ import json import getpass import datetime import logging -import action +from datetime import datetime +from enum import Enum + +class TypeAction(Enum): + CREATE = 'created' + UPDATE = 'updated' + MOVE = 'moved' class Action: def __init__(self, row): @@ -26,17 +32,37 @@ def handle_action(args, last_action, conn): cursor = conn.cursor() cursor.execute(query) for row in cursor.fetchall(): - result = row - logging.debug(result) + log_id, project_id, task_id, note_id, username, taction, message, created_at = row + logging.debug(row) + object_type = '' + id_object = '' + formated_date = datetime.strptime(created_at[:26], '%Y-%m-%d %H:%M:%S.%f').strftime('%b %d, %Y %H:%M') + + object_type = '' # TODO Enum ? + if (project_id): + object_type = 'project' + id_object = project_id + if (task_id): + object_type = 'task' + id_object = task_id + if (note_id): + object_type = 'note' + id_object = note_id + + print('{} ({}): {} {} {}: {}'.format(formated_date, username, taction, object_type, id_object, message)) -def create_action(cursor, project_id = '', task_id = '', note_id = '', message = ''): + # print('Sep 02, 2017 02:33 (dakota ): updated task 1: Passage à Angular 4 (status: in progress)') +# Sep 02, 2017 02:33 (dakota ): updated task 1: Passage à Angular 4 (status: in progress) +# 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): query = """ - INSERT INTO action (project_id, task_id, note_id, username, message, created_at) - VALUES (?, ?, ?, ?, ?, ?); + 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(), message, datetime.datetime.now(),)) + cursor.execute(query, (project_id, task_id, note_id, getpass.getuser(), action.value, message, datetime.now(),)) logging.debug('created action') diff --git a/pits_schema.sql b/pits_schema.sql index 5624075..dcaa4a2 100644 --- a/pits_schema.sql +++ b/pits_schema.sql @@ -53,6 +53,7 @@ CREATE TABLE action ( task_id integer, -- Task id (set for task or note related actions). note_id integer, -- Note id (set for note related actions only). username text, -- Who added the log message? + action text, -- What type of action ? (updated, created, etc.) message text, -- Log message. created_at date -- When log message was added? ); diff --git a/project.py b/project.py index 305fe6f..2a5f518 100644 --- a/project.py +++ b/project.py @@ -45,8 +45,8 @@ def create_project(args, conn): cursor.execute(query, (getpass.getuser(), args.create_name, status, datetime.datetime.now(),)) project_id = cursor.lastrowid - - action.create_action(cursor, project_id=project_id) + action_message = '{} (status: {})'.format(args.create_name, status) + action.create_action(cursor, project_id=project_id, message=action_message) print('created project {}: {} (status: {})'.format(project_id, args.create_name, status)) @@ -100,6 +100,7 @@ def list_project(active_project_id, conn): cursor = conn.cursor() cursor.execute(query) for row in cursor.fetchall(): + logging.debug('Project row: {}'.format(row)) project_id, username, name, status, date, nb_task = row print('{:1} {:2d}: ({:8}) | {} | {} ({} tasks)'.format('*' if active_project_id == project_id else '', project_id, username, status, name, nb_task)) \ No newline at end of file diff --git a/task.py b/task.py index dad82d4..d032657 100644 --- a/task.py +++ b/task.py @@ -58,8 +58,12 @@ def create_task(args, active_project_id, conn): task_id = cursor.lastrowid logging.debug('CREATE ACTION ' + str(active_project_id) + str(task_id) ) - action.create_action(cursor, project_id=active_project_id, task_id=task_id) + action_message = '{} (status: {}, priority: {}, project: {})'.format(args.create_name, status, priority, + active_project_id) + # TODO if date/time/other => add to message + + action.create_action(cursor, project_id=active_project_id, task_id=task_id, message=action_message) print('created task {}: {} (status: {})'.format(task_id, args.create_name, status)) def edit_task(args, task_id, conn): @@ -85,7 +89,11 @@ def edit_task(args, task_id, conn): else: print('updated task {}: set active task') - action.create_action(cursor, task_id, message = 'update ' + str(update_args)) + # TODO If not edit name... => retrieve name ? + # TODO Retrieve project id ? + action_message = '{} ({})'.format(args.edit_name, ', '.join("%s: %s" % (k, v) for k, v in update_args.items())) + logging.debug('UPDATE TASK - ACTION MESSAGE : ' + action_message) + action.create_action(cursor, task_id=task_id, action=action.TypeAction.UPDATE, message = action_message) def moving_task(args): print('moving')