Create task

This commit is contained in:
2018-07-09 02:13:24 +02:00
parent f19965f1a1
commit a0cc2e1e02
3 changed files with 39 additions and 33 deletions

View File

@@ -55,6 +55,7 @@ def init():
db_is_new = not os.path.exists(db_path)
if not db_is_new:
print('Database already exist')
# TODO Permit to override
return
with sqlite3.connect(db_path) as conn:

View File

@@ -30,20 +30,21 @@ def handle_project(args, last_action, conn):
if args[0] == '-c':
if len(args) == 1:
print('required project name')
print('missing project name')
sys.exit(1)
project = Project()
project.name = arg_string(args[1], 'project name')
create_project(project, conn)
elif args[0] == '-e':
print('Update project')
print('TODO Update project')
elif args[0] == '-d':
if len(args) > 1:
delete_project(arg_number(args[1]), conn)
else:
delete_project(last_action.project_id, conn)
# TODO Move this function
def arg_string(arg, required = ''):
if required and arg.startswith('-'):
print('required ', required)

64
task.py
View File

@@ -5,37 +5,39 @@ import json
import getpass
import datetime
import logging
import sys
import action
import project
class Task:
def __init__(self):
self.name = ''
self.status = 'open'
self.priority = 'normal'
def handle_task(args, last_action, conn):
logging.info('> handle task')
logging.debug('args: ' + str(args))
logging.debug('Last action: {}'.format(last_action))
do_something = False
if args.create_name:
do_something = True
create_task(args, last_action.project_id, conn)
if args.delete_id:
do_something = True
delete_task(args.delete_id, conn)
if args.moving_id:
do_something = True
moving_task(args)
if args.edit_id:
do_something = True
edit_task(args, args.edit_id, conn)
if not do_something:
if not args:
list_task(last_action.project_id, last_action.task_id, conn)
sys.exit(0)
def create_task(args, active_project_id, conn):
if args[0].isdigit():
view_task()
sys.exit(0)
if args[0] == '-c':
if len(args) == 1:
print('missing task name')
sys.exit(1)
task = Task()
task.name = project.arg_string(args[1], 'task name')
create_task(task, last_action.project_id, conn)
def create_task(task, active_project_id, conn):
# TODO Don't create task if no project (nothing selected?) ==> foreign key is not a solution: there is no project ID :)
logging.info('>> Create task')
@@ -45,26 +47,24 @@ def create_task(args, active_project_id, conn):
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
"""
status = 'open'
priority = 'normal'
# TODO Date & time
date = ''
time = ''
cursor = conn.cursor()
cursor.execute(query, (active_project_id, getpass.getuser(), args.create_name, status, priority, date, time,
datetime.datetime.now(),))
cursor.execute(query, (active_project_id, getpass.getuser(), task.name, task.status,
task.priority, date, time, datetime.datetime.now(),))
task_id = cursor.lastrowid
logging.debug('CREATE ACTION ' + str(active_project_id) + str(task_id) )
action_message = '{} (status: {}, priority: {}, project: {})'.format(args.create_name, status, priority,
active_project_id)
action_message = '{} (status: {}, priority: {}, project: {})'.format(task.name,
task.status, task.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))
print('created task {}: {} (status: {})'.format(task_id, task.name, task.status))
def edit_task(args, task_id, conn):
logging.info('>> Edit task')
@@ -121,8 +121,12 @@ def list_task(active_project_id, active_task_id, conn):
for row in cursor.fetchall():
nb_note = 0
task_id, username, status, priority, name = row
print('{:1} {:2d}: ({:8}) | {} | {} | {} ({} tasks )'.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))
# TODO Note
# 2: (budd) |open| |normal| test (0 notes)
# * 3: (budd) |open| |normal| Dec 31, 2018 tet (0 notes)
def view_task():
print('TODO View Task')