WIP on action/log

This commit is contained in:
2018-07-05 01:01:18 +02:00
parent bee3fd96b5
commit e421731608
4 changed files with 48 additions and 12 deletions

View File

@@ -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')