Create note
This commit is contained in:
42
note.py
42
note.py
@@ -5,33 +5,35 @@ import json
|
||||
import getpass
|
||||
import datetime
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import action
|
||||
import project
|
||||
|
||||
class Note:
|
||||
def __init__(self):
|
||||
self.message = ''
|
||||
|
||||
def handle_note(args, last_action, conn):
|
||||
logging.info('> handle note')
|
||||
logging.debug('args: ' + str(args))
|
||||
|
||||
logging.debug('Last action: {}'.format(last_action))
|
||||
|
||||
do_something = False
|
||||
|
||||
if args.create_name:
|
||||
do_something = True
|
||||
create_note(args, last_action.project_id, last_action.task_id, conn)
|
||||
|
||||
if args.delete_id:
|
||||
do_something = True
|
||||
delete_note(args.delete_id, conn)
|
||||
|
||||
if args.edit_id:
|
||||
do_something = True
|
||||
edit_note(args, args.edit_id, conn)
|
||||
|
||||
if not do_something:
|
||||
if not args:
|
||||
list_note(last_action.project_id, last_action.task_id, last_action.note_id, conn)
|
||||
sys.exit(0)
|
||||
|
||||
def create_note(args, active_project_id, active_task_id, conn):
|
||||
# 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')
|
||||
create_note(note, last_action.project_id, last_action.task_id, conn)
|
||||
|
||||
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 :)
|
||||
logging.info('>> Create note')
|
||||
|
||||
@@ -41,13 +43,13 @@ def create_note(args, active_project_id, active_task_id, conn):
|
||||
"""
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (active_project_id, active_task_id, getpass.getuser(), args.create_name))
|
||||
cursor.execute(query, (active_project_id, active_task_id, getpass.getuser(), note.message))
|
||||
|
||||
note_id = cursor.lastrowid
|
||||
|
||||
action.create_action(cursor, project_id=active_project_id, task_id = active_task_id, note_id=note_id)
|
||||
|
||||
print('created note {}: {} (task {})'.format(note_id, args.create_name, active_task_id))
|
||||
print('created note {}: {} (task {})'.format(note_id, note.message, active_task_id))
|
||||
|
||||
def edit_note(args, note_id, conn):
|
||||
logging.info('>> Edit note')
|
||||
|
||||
Reference in New Issue
Block a user