Notes
This commit is contained in:
69
note.py
69
note.py
@@ -10,9 +10,12 @@ import sys
|
||||
import action
|
||||
import project
|
||||
|
||||
from args import get_string_arg
|
||||
from args import arg_number
|
||||
|
||||
class Note:
|
||||
def __init__(self):
|
||||
self.message = ''
|
||||
self.message = None
|
||||
|
||||
def handle_note(args, last_action, conn):
|
||||
logging.info('> handle note')
|
||||
@@ -22,16 +25,39 @@ def handle_note(args, last_action, conn):
|
||||
list_note(last_action.project_id, last_action.task_id, last_action.note_id, conn)
|
||||
sys.exit(0)
|
||||
|
||||
# if arg[1] is digit ==> bad parameter
|
||||
|
||||
if args[0] == '-c':
|
||||
if len(args) == 1:
|
||||
print('missing note message')
|
||||
sys.exit(1)
|
||||
|
||||
note = Note()
|
||||
note.message = project.arg_string(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:
|
||||
print('nothing to update')
|
||||
|
||||
note = Note()
|
||||
args_i = 1
|
||||
note_id = last_action.note_id
|
||||
if args[args_i].isdigit():
|
||||
note_id = arg_number(args[args_i])
|
||||
args_i += 1
|
||||
|
||||
if not note_id:
|
||||
print('No active note to update')
|
||||
sys.exit(1)
|
||||
|
||||
note.message = get_string_arg(args[args_i:], 'note message')
|
||||
edit_note(note, note_id, last_action, conn)
|
||||
elif args[0] == '-d':
|
||||
# FIXME Duplicate code
|
||||
if len(args) > 1:
|
||||
delete_note(arg_number(args[1]), conn)
|
||||
else:
|
||||
delete_note(last_action.task_id, conn)
|
||||
else:
|
||||
print(f'Invalid note option: {args[0]}')
|
||||
|
||||
def create_note(note, active_project_id, active_task_id, conn):
|
||||
# TODO Don't create note if no project (nothing selected?) ==> foreign key is not a solution: there is no project ID :)
|
||||
@@ -51,30 +77,21 @@ def create_note(note, active_project_id, active_task_id, conn):
|
||||
|
||||
print('created note {}: {} (task {})'.format(note_id, note.message, active_task_id))
|
||||
|
||||
def edit_note(args, note_id, conn):
|
||||
def edit_note(note, note_id, last_action, conn):
|
||||
logging.info('>> Edit note')
|
||||
|
||||
update_args = {}
|
||||
if args.status:
|
||||
update_args['status'] = args.status
|
||||
if args.edit_name:
|
||||
update_args['name'] = args.edit_name
|
||||
|
||||
query = 'UPDATE note SET {} WHERE id = ?'
|
||||
query = query.format(', '.join("%s = '%s'" % (k, v) for k, v in update_args.items()))
|
||||
logging.debug('update note query: ' + query)
|
||||
query = 'UPDATE note SET message = ? WHERE id = ?'
|
||||
|
||||
cursor = conn.cursor()
|
||||
if update_args:
|
||||
logging.debug('Do a note update')
|
||||
cursor.execute(query, (note_id,))
|
||||
cursor.execute(query, (note.message, note_id,))
|
||||
|
||||
log_args = ', '.join("%s: '%s'" % (k, v) for k, v in update_args.items())
|
||||
print('updated note {}: ({})'.format(note_id, log_args))
|
||||
else:
|
||||
print('updated note {}: set active note')
|
||||
if cursor.rowcount != 1:
|
||||
logging.error('UPDATE FAILED')
|
||||
print('could not find note {}'.format(note_id))
|
||||
sys.exit(1)
|
||||
|
||||
action.create_action(cursor, note_id, message = 'update ' + str(update_args))
|
||||
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')
|
||||
@@ -88,6 +105,9 @@ def delete_note(note_id, conn):
|
||||
cursor.execute(query, (note_id,))
|
||||
if cursor.rowcount != 1:
|
||||
logging.error('DELETE FAILED')
|
||||
print('could not find note {}'.format(note_id))
|
||||
sys.exit(1)
|
||||
|
||||
print('deleted note {}: {}'.format(note_id, 'note_name'))
|
||||
|
||||
def list_note(active_project_id, active_task_id, active_note_id, conn):
|
||||
@@ -98,7 +118,4 @@ def list_note(active_project_id, active_task_id, active_note_id, conn):
|
||||
cursor.execute(query, (active_project_id, active_task_id))
|
||||
for row in cursor.fetchall():
|
||||
note_id, username, message = row
|
||||
print('{:1} {:2d}: ({:8}) {}'.format('*' if active_note_id == note_id else '', note_id, username, message))
|
||||
|
||||
# 2: (budd) |open| |normal| test (0 notes)
|
||||
# * 3: (budd) |open| |normal| Dec 31, 2018 tet (0 notes)
|
||||
print('{:1} {:2d}: ({:8}) {}'.format('*' if active_note_id == note_id else '', note_id, username, message))
|
||||
Reference in New Issue
Block a user