def completetask(): if 'userid' in session: user = User.query.get_or_404(session['userid']) if request.method == 'POST': form = TaskIdForm(request.form) if form.validate(): task = Task.query.get_or_404(form.taskid.data) task.complete = True task.datecomplete = datetime.utcnow() user.points += task.value db.session.commit() return redirect(url_for('tasks')) else: return redirect(url_for('tasks')) else: return redirect(url_for('front'))
def taskupdate(): if 'userid' in session: user = User.query.get_or_404(session['userid']) if request.method == 'POST': updateform = TaskUpdateForm(request.form) if updateform.validate(): task = Task.query.get_or_404(updateform.taskid.data) if task.userid == user.id: # update fields task.title = updateform.title.data task.value = updateform.value.data #task.datedue = updateform.datedue.data db.session.commit() return redirect(url_for('tasks')) else: tasks = user.tasks.filter(Task.complete == False).order_by( desc(Task.dateadded)).all() return render_template('tasks.html', username=user.username, points=user.points, tasks=tasks, form=TaskForm(), idform=TaskIdForm(), updateform=updateform, containerclass="listcontainer") else: return redirect(url_for('tasks')) else: return redirect(url_for('front'))
def deltask(): if 'userid' in session: user = User.query.get_or_404(session['userid']) if request.method == 'POST': form = TaskIdForm(request.form) if form.validate(): task = Task.query.get_or_404(form.taskid.data) # change this to hide tasks, but leave them in the database? if task.userid == user.id: db.session.delete(task) db.session.commit() if form.referpage.data == "completed": return redirect(url_for('completed')) else: return redirect(url_for('tasks')) else: return redirect(url_for('tasks')) else: return redirect(url_for('front'))
def tasks(): if 'userid' in session: user = User.query.get_or_404(session['userid']) if request.method == 'POST': form = TaskForm(request.form) if form.validate(): newtask = Task(form.title.data, user, None, form.value.data) db.session.add(newtask) db.session.commit() return redirect(url_for('tasks')) else: tasks = user.tasks.filter(Task.complete == False).order_by( desc(Task.dateadded)).all() return render_template('tasks.html', username=user.username, points=user.points, tasks=tasks, form=form, idform=TaskIdForm(), updateform=TaskUpdateForm(), containerclass="listcontainer") else: tasks = user.tasks.filter(Task.complete == False).order_by( desc(Task.dateadded)).all() return render_template('tasks.html', username=user.username, points=user.points, tasks=tasks, form=TaskForm(), idform=TaskIdForm(), updateform=TaskUpdateForm(), containerclass="listcontainer") # if no session, display default home page. TODO: convert to splash page else: return redirect(url_for('front'))
def completed(): if 'userid' in session: user = User.query.get_or_404(session['userid']) comptasks = user.tasks.filter(Task.complete == True).order_by( desc(Task.datecomplete)).all() return render_template('completed.html', username=user.username, points=user.points, comptasks=comptasks, idform=TaskIdForm(), containerclass="listcontainer") # if no session, display default home page. TODO: convert to splash page else: return redirect(url_for('front'))