Esempio n. 1
0
def update(id):
    form = TodoForm()
    todo = Todos.query.get(id)
    if form.validate_on_submit():
        todo.task = form.task.data
        db.session.commit()
        redirect(url_for('index'))
    elif request.method == 'GET':
        form.task.data = todo.task
    return render_template('update.html', title='Update your todo', form=form)
Esempio n. 2
0
def update(todo_id):
    form = TodoForm()
    todo_to_update = Todos.query.get(todo_id)
    if form.validate_on_submit():
        todo_to_update.task = form.task.data
        db.session.commit()
        return redirect(url_for('index'))
    elif request.method == "GET":
        form.task.data = todo_to_update.task
    return render_template('update.html', form=form)
Esempio n. 3
0
def add():
    form = TodoForm()
    if form.validate_on_submit():
        todo = Todos(
            task = form.task.data,
            complete = False
        )
        db.session.add(todo)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('add.html', title="Add a new todo", form=form)
Esempio n. 4
0
def add():
    error = ""
    form = TodoForm()

    if request.method == 'POST':
        if form.validate_on_submit():
            name = form.name.data
            todo = Todos(name=name)
            db.session.add(todo)
            db.session.commit()
            return redirect(url_for('index'))
    return render_template('add.html', form=form)