diff --git a/db_interaction.py b/db_interaction.py index 6b149b9..f9a0359 100644 --- a/db_interaction.py +++ b/db_interaction.py @@ -16,6 +16,7 @@ ''' import sqlite3 +import operator def db_insert_task(text, urgent): @@ -55,7 +56,7 @@ def get_sorted_tasks_list(): ''' tasks_list = [] - sql = "SELECT todo FROM task order by todo ASC" #here we order data using "order by" + sql = "SELECT id_task, todo FROM task order by todo ASC" #here we order data using "order by" conn = sqlite3.connect("task_list.db") # to remove u from sqlite3 cursor.fetchall() results @@ -70,13 +71,13 @@ def get_sorted_tasks_list(): # print results for task in results: - tasks_list.append(task[0]) #each "task" is a tuple, so we have to take the first element of it + tasks_list.append((task[0],task[1])) #each "task" is a tuple, so we have to take the first element of it conn.close() return tasks_list -def db_remove_task(text): +def db_remove_task_by_id(id_task): ''' :param text: text (or part of it) of the task we want to remove from the db @@ -84,11 +85,8 @@ def db_remove_task(text): ''' # prepare the query text - sql = "delete from task where todo LIKE ?" + sql = "delete from task where id_task = ?" - # add percent sign (%) wildcard to select all the strings that contain specified text - # <> - text = "%"+text + "%" #connect to the db conn = sqlite3.connect("task_list.db") @@ -96,7 +94,7 @@ def db_remove_task(text): try: #execute the query passing the needed parameters - cursor.execute(sql, (text, ) ) + cursor.execute(sql, (id_task, ) ) #commit all pending executed queries in the connection conn.commit() except Exception,e: diff --git a/task_list.db b/task_list.db index 8905f19..b475bf3 100644 Binary files a/task_list.db and b/task_list.db differ diff --git a/templates/index.html b/templates/index.html index 9872242..494cd71 100644 --- a/templates/index.html +++ b/templates/index.html @@ -9,7 +9,7 @@

Welcome to the Todo List Manager

Here you can see all existing tasks

diff --git a/todo_list_flask.py b/todo_list_flask.py index a280ef1..3e712d7 100644 --- a/todo_list_flask.py +++ b/todo_list_flask.py @@ -48,9 +48,9 @@ def insert_task(): @app.route('/delete_task.html', methods=['GET']) def delete_task(): - if 'string_for_delete' in request.args: - string_for_delete = request.args.get('string_for_delete') - db_interaction.db_remove_task(string_for_delete) + if 'id_task' in request.args: + id_task = request.args.get('id_task') + db_interaction.db_remove_task_by_id(id_task) # back to the home page return redirect(url_for('index'))