from flask import Blueprint, render_template
from organise.models import Todo
from organise import db
from flask import render_template, request, redirect, url_for, flash

todos = Blueprint('todos', __name__, template_folder='/../templates')

@todos.route('/')
def index():
    all_todos = Todo.query.order_by(Todo.id.desc()).all()
    return render_template('todos.html', all_todos=all_todos)


@todos.route('/add', methods=['POST'])
def add_todo():
    todo = Todo(request.form['title'], request.form['description'])
    db.session.add(todo)
    db.session.commit()
    flash('New todo was added!')
    return redirect(url_for('todos.index'))


@todos.route('/todo/<int:t_id>')
def show_todo(t_id):
    todo = Todo.query.filter_by(id=t_id).first()
    return render_template('todo.html', todo=todo)


@todos.route('/todo/<int:t_id>/edit')
def edit_todo(t_id):
    pass


@todos.route('/todo/<int:t_id>/delete', methods=['POST'])
def delete_todo(t_id):
    pass

@@ -594,9 +594,8 @@
 dded
-!
 ')%0A 
@@ -831,16 +831,34 @@
 d%3E/edit'
+, methods=%5B'POST'%5D
 )%0Adef ed
@@ -880,101 +880,566 @@
     
-pass%0A%0A%0A@todos.route('/todo/%3Cint:t_id%3E/delete', methods=%5B'POST'%5D)%0Adef delete_todo(t_id):%0A    pass
+changed_title = request.form%5B'title'%5D%0A    changed_description = request.form%5B'description'%5D%0A    todo = Todo.query.filter_by(id=t_id).first()%0A    todo.title = changed_title%0A    todo.description = changed_description%0A    db.session.commit()%0A    flash('All changes were saved')%0A    return redirect(url_for('todos.show_todo', t_id=t_id))%0A%0A%0A@todos.route('/todo/%3Cint:t_id%3E/delete', methods=%5B'POST'%5D)%0Adef delete_todo(t_id):%0A    todo = Todo.query.filter_by(id=t_id).first()%0A    db.session.delete(todo)%0A    db.session.commit()%0A    return redirect(url_for('todos.index'))
 %0A

Add functionality for edit and delete functions