Split project class
This commit is contained in:
68
project.py
68
project.py
@@ -12,16 +12,26 @@ schema_filename = 'pits_schema.sql'
|
||||
|
||||
def handle_project(args, last_action):
|
||||
logging.info('> handle project')
|
||||
logging.debug('args: args')
|
||||
|
||||
status = 'active'
|
||||
if args.status:
|
||||
status = args.status
|
||||
logging.debug('args: ' + str(args))
|
||||
|
||||
do_something = False
|
||||
|
||||
if args.create_name:
|
||||
do_something = True
|
||||
create_project(args)
|
||||
|
||||
if args.delete_id:
|
||||
do_something = True
|
||||
delete_project(args.delete_id)
|
||||
|
||||
if args.edit_id:
|
||||
do_something = True
|
||||
edit_project(args, args.edit_id)
|
||||
|
||||
if not do_something:
|
||||
list_project(last_action[0])
|
||||
|
||||
def create_project(args):
|
||||
# TODO Project is same name is forbidden
|
||||
logging.info('>> Create project')
|
||||
|
||||
@@ -30,6 +40,9 @@ def handle_project(args, last_action):
|
||||
VALUES (?, ?, ?, ?);
|
||||
"""
|
||||
|
||||
status = 'active'
|
||||
if args.status: status = args.status
|
||||
|
||||
with sqlite3.connect(db_filename) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (getpass.getuser(), args.create_name, status, datetime.datetime.now(),))
|
||||
@@ -40,25 +53,7 @@ def handle_project(args, last_action):
|
||||
|
||||
print('created project {}: {} (status: {})'.format(project_id, args.create_name, status))
|
||||
|
||||
if args.delete_id:
|
||||
do_something = True
|
||||
logging.info('>> Remove project')
|
||||
|
||||
query = """
|
||||
DELETE FROM project
|
||||
WHERE id = ?;
|
||||
"""
|
||||
|
||||
with sqlite3.connect(db_filename) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (args.delete_id,))
|
||||
if cursor.rowcount != 1:
|
||||
logging.error('DELETE FAILED')
|
||||
print('deleted project {}: {}'.format(args.delete_id, 'project_name'))
|
||||
|
||||
if args.edit_id:
|
||||
project_id = args.edit_id
|
||||
do_something = True
|
||||
def edit_project(args, project_id):
|
||||
logging.info('>> Edit project')
|
||||
|
||||
update_args = {}
|
||||
@@ -84,7 +79,22 @@ def handle_project(args, last_action):
|
||||
|
||||
action.create_action(cursor, project_id, message = 'update ' + str(update_args))
|
||||
|
||||
if not do_something:
|
||||
def delete_project(project_id):
|
||||
logging.info('>> Remove project')
|
||||
|
||||
query = """
|
||||
DELETE FROM project
|
||||
WHERE id = ?;
|
||||
"""
|
||||
|
||||
with sqlite3.connect(db_filename) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query, (project_id,))
|
||||
if cursor.rowcount != 1:
|
||||
logging.error('DELETE FAILED')
|
||||
print('deleted project {}: {}'.format(project_id, 'project_name'))
|
||||
|
||||
def list_project(active_project_id):
|
||||
logging.info('>> No arguments')
|
||||
query = "SELECT id, username, name, status, created_at FROM project;"
|
||||
with sqlite3.connect(db_filename) as conn:
|
||||
@@ -94,9 +104,5 @@ def handle_project(args, last_action):
|
||||
project_id, username, name, status, date = row
|
||||
nb_task = 0
|
||||
current_project = ''
|
||||
if last_action and last_action[0] == project_id: current_project = '*'
|
||||
print('{} {:2d}: ({:16}) | {} | {} ({} tasks )'.format(current_project, project_id, username, status, name, nb_task))
|
||||
# TODO Print creation date
|
||||
|
||||
# desired output
|
||||
#created project 3: toto (status: active)
|
||||
if active_project_id and active_project_id == project_id: current_project = '*'
|
||||
print('{:1} {:2d}: ({:16}) | {} | {} ({} tasks )'.format(current_project, project_id, username, status, name, nb_task))
|
||||
Reference in New Issue
Block a user