Skip to content

Commit

Permalink
Comments were added to code
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontanaro committed Apr 11, 2016
1 parent f146e88 commit dfbd914
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
12 changes: 4 additions & 8 deletions db_interaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Created on Apr 04, 2016
Created on Apr 11, 2016
Copyright (c) 2015-2016 Teodoro Montanaro
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -50,8 +50,6 @@ def db_insert_task(text, urgent):

def get_sorted_tasks_list():
'''
:param tasks_list: list of existing tasks
Get existing tasks from the database
'''

Expand All @@ -68,20 +66,18 @@ def get_sorted_tasks_list():

results = cursor.fetchall()

# print results

for task in results:
tasks_list.append((task[0],task[1])) #each "task" is a tuple, so we have to take the first element of it
tasks_list.append((task[0],task[1])) #we create a list of tuples (key, value) where key is the task id and the value is the text of the task

conn.close()

return tasks_list

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
:param id_task: unique identificator for the task we want to remove from the db
This method remove from the db all the tasks that contain the specified string
This method remove from the db a specific task
'''

# prepare the query text
Expand Down
Binary file modified task_list.db
Binary file not shown.
13 changes: 11 additions & 2 deletions todo_list_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,39 @@ def hello_world():

@app.route('/index.html')
def index():
#get the ordered list from the database
tasks_list = db_interaction.get_sorted_tasks_list()
return render_template('index.html', tasks_list=tasks_list)


@app.route('/insert_task.html', methods=['POST'])
def insert_task():
# check for parameter received by POST method
if ('description' in request.form and request.form['description']!=''):
#get description (the task)
description = request.form['description']
# transform value received through the checkbox in a 0/1 value
if ('urgent' in request.form and request.form['urgent'] == 'on'):
urgent = 1
else:
urgent = 0
#insert the new task in the database
db_interaction.db_insert_task(description, urgent)

# back to the home page
# redirect to the home page
return redirect(url_for('index'))

@app.route('/delete_task.html', methods=['GET'])
def delete_task():

# check for parameter received by GET method
if 'id_task' in request.args:
#get the id of the task we want to remove
id_task = request.args.get('id_task')
# remove the item from the db
db_interaction.db_remove_task_by_id(id_task)

# back to the home page
# redirect to the home page
return redirect(url_for('index'))


Expand Down

0 comments on commit dfbd914

Please sign in to comment.