From 9e18882c5e46355eb6762afed7ac16de0b02b9d2 Mon Sep 17 00:00:00 2001 From: Arnas Udovicius Date: Fri, 16 Feb 2018 11:16:29 +0200 Subject: [PATCH] manage tags --- model.py | 40 +++++++++++++++++---- task.py | 9 +++-- ztm.py | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 146 insertions(+), 10 deletions(-) diff --git a/model.py b/model.py index ae38c51..aa95965 100644 --- a/model.py +++ b/model.py @@ -20,9 +20,7 @@ class Model: return self.conn.execute(query, tag_name) def get_all_tasks(self): - query = ''' - SELECT t.* FROM task t - ''' + query = 'SELECT t.* FROM task t' return self.conn.execute(query) @@ -59,17 +57,47 @@ class Model: def save_content(self, aid, content): cursor = self.conn.cursor() cursor.execute('UPDATE task SET content=? WHERE aid=?', (content, aid)) - self.conn.commit() def toggle_long_term(self, aid): cursor = self.conn.cursor() cursor.execute('UPDATE task SET long_term=NOT long_term WHERE aid=?', (aid)) - self.conn.commit() def toggle_done(self, aid): cursor = self.conn.cursor() cursor.execute('UPDATE task SET done=NOT done, finished_at=DATETIME(\'now\') WHERE aid=?', (aid)) - + self.conn.commit() + + def create_tag(self, name): + query = 'INSERT INTO tag (name) VALUES (?)' + cursor = self.conn.cursor() + cursor.execute(query, (name,)) + self.conn.commit() + + return cursor.lastrowid + + def get_all_tags(self): + query = 'SELECT t.* FROM tag t' + + return self.conn.execute(query) + + def get_tag(self, tid): + query = 'SELECT t.* FROM tag t WHERE t.id = ?' + cursor = self.conn.cursor() + results = cursor.execute(query, (tid,)) + + return results.fetchone() + + def get_tag_by_name(self, name): + query = 'SELECT t.* FROM tag t WHERE t.name = ?' + cursor = self.conn.cursor() + results = cursor.execute(query, (name,)) + + return results.fetchone() + + def remove_tag_by_name(self, name): + query = 'DELETE FROM tag WHERE name = ?' + cursor = self.conn.cursor() + cursor.execute(query, (name,)) self.conn.commit() diff --git a/task.py b/task.py index 44bf6cd..e470bb0 100644 --- a/task.py +++ b/task.py @@ -21,7 +21,7 @@ class Task: self.add() tasksData = self.model.get_all_tasks() - for t in self.model.get_all_tasks(): + for t in tasksData: tasks.append('%s: %s' % (t['aid'], t['description'])) selected = self.fzf.prompt(tasks) @@ -37,11 +37,12 @@ class Task: print('\n' + bcolors.HEADER + 'Adding task\n' + bcolors.ENDC) description = input('Description: ') aid = self.model.create_task_draft(description) + print(bcolors.OKBLUE + '\n[task has been created]' + bcolors.ENDC) self.manage_task(aid) def manage_task(self, aid): task = self.model.get_task(aid) - print('\n' + bcolors.HEADER + 'Managing: [' + task['aid'] + '] ' + task['description'] + bcolors.ENDC) + print('\n' + bcolors.HEADER + 'Managing task: [' + task['aid'] + '] ' + task['description'] + bcolors.ENDC) long_term = ' ' if task['long_term'] and task['long_term'] != 'FALSE': @@ -61,7 +62,7 @@ Created: %s self.manage_task_menu(aid) def manage_task_menu(self, aid): - menu = input(bcolors.OKGREEN + 'What you want to do? (?e*+-v&>