Create note
This commit is contained in:
42
note.py
42
note.py
@@ -5,33 +5,35 @@ import json
|
|||||||
import getpass
|
import getpass
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
import action
|
import action
|
||||||
|
import project
|
||||||
|
|
||||||
|
class Note:
|
||||||
|
def __init__(self):
|
||||||
|
self.message = ''
|
||||||
|
|
||||||
def handle_note(args, last_action, conn):
|
def handle_note(args, last_action, conn):
|
||||||
logging.info('> handle note')
|
logging.info('> handle note')
|
||||||
logging.debug('args: ' + str(args))
|
logging.debug('args: ' + str(args))
|
||||||
|
|
||||||
logging.debug('Last action: {}'.format(last_action))
|
if not args:
|
||||||
|
|
||||||
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:
|
|
||||||
list_note(last_action.project_id, last_action.task_id, last_action.note_id, conn)
|
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 :)
|
# 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')
|
logging.info('>> Create note')
|
||||||
|
|
||||||
@@ -41,13 +43,13 @@ def create_note(args, active_project_id, active_task_id, conn):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
cursor = conn.cursor()
|
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
|
note_id = cursor.lastrowid
|
||||||
|
|
||||||
action.create_action(cursor, project_id=active_project_id, task_id = active_task_id, note_id=note_id)
|
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):
|
def edit_note(args, note_id, conn):
|
||||||
logging.info('>> Edit note')
|
logging.info('>> Edit note')
|
||||||
|
|||||||
16
task.py
16
task.py
@@ -114,13 +114,23 @@ def delete_task(task_id, conn):
|
|||||||
|
|
||||||
def list_task(active_project_id, active_task_id, conn):
|
def list_task(active_project_id, active_task_id, conn):
|
||||||
logging.info('>> No arguments')
|
logging.info('>> No arguments')
|
||||||
query = "SELECT id, username, status, priority, name FROM task WHERE project_id = ?;" #TODO Date & time
|
|
||||||
|
query = """
|
||||||
|
SELECT id, username, name, status, created_at,
|
||||||
|
(SELECT count(*) FROM task WHERE task.project_id = project.id)
|
||||||
|
FROM project;
|
||||||
|
"""
|
||||||
|
|
||||||
|
query = """
|
||||||
|
SELECT id, username, status, priority, name,
|
||||||
|
(SELECT count(*) FROM note WHERE note.task_id = task.id)
|
||||||
|
FROM task WHERE project_id = ?;
|
||||||
|
""" #TODO Date & time
|
||||||
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query, (active_project_id,))
|
cursor.execute(query, (active_project_id,))
|
||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
nb_note = 0
|
task_id, username, status, priority, name, nb_note = row
|
||||||
task_id, username, status, priority, name = row
|
|
||||||
print('{:1} {:2d}: ({:8}) | {} | {} | {} ({} notes)'.format('*' if active_task_id == task_id else '', task_id,
|
print('{:1} {:2d}: ({:8}) | {} | {} | {} ({} notes)'.format('*' if active_task_id == task_id else '', task_id,
|
||||||
username, status, priority, name, nb_note))
|
username, status, priority, name, nb_note))
|
||||||
# TODO Note
|
# TODO Note
|
||||||
|
|||||||
Reference in New Issue
Block a user