def todolist(id): todolist = TodoList.query.filter_by(id=id).first_or_404() form = TodoForm() if form.validate_on_submit(): Todo(form.todo.data, todolist.id, _get_user()).save() return redirect(url_for("main.todolist", id=id)) return render_template("todolist.html", todolist=todolist, form=form)
def new_todolist(): form = TodoForm(todo=request.form.get("todo")) if form.validate(): todolist = TodoList(creator=_get_user()).save() Todo(form.todo.data, todolist.id).save() return redirect(url_for("main.todolist", id=todolist.id)) return redirect(url_for("main.index"))
async def add(): form = TodoForm() if form.validate_on_submit(): task = Todo(task=form.task.data) db.session.add(task) db.session.commit() return redirect(url_for("main.home"))
def index(): form1 = TodoForm() if form1.validate_on_submit(): day = form1.day.data month = form1.month.data year = form1.year.data hour = form1.hour.data minute = form1.minute.data a_p = form1.a_p.data date_str = year + '-' + month + '-' + day + '-' \ + hour + '-' + minute + '-' + a_p datetime_obj = datetime.strptime(date_str, '%Y-%b-%d-%I-%M-%p') datetime_obj = datetime.astimezone(datetime_obj, pytz.UTC) sanitized = html.escape(form1.todo.data) todo = Todo(body=sanitized, author=current_user, due_date=datetime_obj) db.session.add(todo) db.session.commit() return redirect(url_for('main.index')) page = request.args.get('page', 1, type=int) todos = current_user.all_todos().paginate( page, current_app.config['TODOS_PER_PAGE'], False) next_url = url_for('main.index', page=todos.next_num) \ if todos.has_next else None prev_url = url_for('main.index', page=todos.prev_num) \ if todos.has_prev else None return render_template('index.html', title=_('Home'), form=form1, todos=todos.items, next_url=next_url, prev_url=prev_url)
def settings(): """Return CRUD view for User data""" (lat, lon) = (current_user.latitude, current_user.longitude) userStocks = current_user.stocks.all() stockList = [stock.symbol for stock in userStocks] userTodos = current_user.todos.all() todoList = [(todo.id, todo.todo) for todo in userTodos] userEmbeds = current_user.embeds.all() embedList = [(embed.embed, embed.name) for embed in userEmbeds] # TODO move all forms to top locationForm = LocationForm() # TODO move `if` blocks to a func if locationForm.submitLoc.data and locationForm.validate_on_submit(): current_user.set_location(locationForm.lat.data, locationForm.lon.data) db.session.commit() flash('Updated location.') return redirect('/settings') stockForm = StockForm() if stockForm.submitStock.data and stockForm.validate_on_submit(): stock = Stock(symbol=stockForm.symbol.data, author=current_user) db.session.add(stock) db.session.commit() flash('Added stock!') return redirect('/settings') todoForm = TodoForm() if todoForm.submitTodo.data and todoForm.validate_on_submit(): todo = Todo(todo=todoForm.todo.data, author=current_user) db.session.add(todo) db.session.commit() flash('Added todo!') return redirect('/settings') embedForm = EmbedForm() if embedForm.submitEmbed.data and embedForm.validate_on_submit(): embed = Embed(embed=embedForm.embed.data, name=embedForm.name.data, author=current_user) db.session.add(embed) db.session.commit() flash('Added embed!') return redirect('/settings') return render_template('settings.html', stocks=stockList, stockForm=stockForm, todoForm=todoForm, todos=todoList, embedForm=embedForm, embeds=embedList, locationForm=locationForm, lat=lat, lon=lon)
def add_todo(): '''add a todo for your courses''' form = TodoForm() if form.validate_on_submit(): new_todo = Todo( description = form.description.data, todo_for_course = form.todo_for_course.data, ) db.session.add(new_todo) db.session.commit() flash('Great! let\'s get to work!') return redirect(url_for('main.display_todos', course_id=new_todo.course_id )) return render_template('add_todo.html', form=form,)
def index(): form = TodoForm() if form.validate_on_submit(): return redirect(url_for("main.new_todolist")) return render_template("index.html", form=form)
async def home(): form = TodoForm() todos = Todo.query.filter_by(is_completed=False).order_by( Todo.id.desc()).all() return await render_template("index.html", todos=todos, form=form)