def addTodo_page(): form = TodoForm() id = current_user.id #request.args.get("user") if request.args.get("action") == 'add': if form.validate_on_submit(): print('form executed') todo_to_create = Todo(name=form.name.data, category=form.category.data, owner=id) db.session.add(todo_to_create) db.session.commit() print('db executed') return redirect(url_for('dashboard_page', page_num=1)) if form.errors != {}: for err_msg in form.errors.values(): flash(err_msg) if request.args.get("action") == "edit": idTodo = request.args.get("todo") todo = Todo.query.filter_by(id=idTodo).first() if form.validate_on_submit(): todo.name = form.name.data todo.category = form.category.data db.session.commit() return redirect(url_for('dashboard_page')) return render_template('addTodo.html', form=form, todo=todo, action='edit') return render_template('addTodo.html', form=form)
def home(): todo_form = TodoForm() if todo_form.validate_on_submit(): task = Todo(title=todo_form.task.data, priority=todo_form.priority.data, status='In Progress', user_id=current_user.id) db.session.add(task) db.session.commit() flash('Your task has been added!', 'success') return redirect(url_for('home')) if request.method == 'GET': tasks = Todo.query.order_by(Todo.date_posted).filter_by(user_id=current_user.id, status="In Progress") return render_template('home.html', title='Your things todo!', todo_form=todo_form, tasks=tasks)