def done(): conn = conn_f() cursor = conn.cursor() sql = 'UPDATE todo SET done_flag=1 where task_id={0};'.format( request.form['task_id']) cursor.execute(sql) conn.commit() cursor.close() conn.close() # indexにリダイレクト return redirect(url_for('index'))
def get_all_tasks(): conn = conn_f() cursor = conn.cursor() # user_idを使う場合(今回はこのsqlは実行しません) # sql = 'select task_id,task_content,done_flag,created_at from todo where user_id= {0};'.format(user_id) sql = 'select task_id,task_content,done_flag,created_at from todo where done_flag = 0;' cursor.execute(sql) tasks = cursor.fetchall() cursor.close() conn.close() return tasks
def update(): conn = conn_f() cursor = conn.cursor() sql = 'UPDATE todo SET task_content="{0}" where task_id={1};'.format( request.form['content'], request.form['task_id']) cursor.execute(sql) conn.commit() cursor.close() conn.close() tasks = get_all_tasks() done_tasks = get_all_done_tasks() # index.htmlにはリストを渡す return render_template('index.html', tasks=list(tasks), done_tasks=list(done_tasks))
def add(): conn = conn_f() cursor = conn.cursor() sql = 'insert into todo(task_content,done_flag,created_at) values("{0}", {1}, "{2}");'.format( request.form['content'], 0, date) cursor.execute(sql) conn.commit() # 接続を閉じる cursor.close() conn.close() # index.htmlにはリストを渡す tasks = get_all_tasks() done_tasks = get_all_done_tasks() # index.htmlにはリストを渡す return render_template('index.html', tasks=list(tasks), done_tasks=list(done_tasks))