def redeem(): if 'userid' in session: user = User.query.get_or_404(session['userid']) if request.method == 'POST': form = RewardIdForm(request.form) if form.validate(): reward = Reward.query.get_or_404(form.rewardid.data) reward.redeemed = True reward.dateredeemed = datetime.utcnow() user.points -= reward.cost db.session.commit() return redirect(url_for('rewards')) else: return redirect(url_for('rewards')) else: return redirect(url_for('front'))
def deletereward(): if 'userid' in session: user = User.query.get_or_404(session['userid']) if request.method == 'POST': form = RewardIdForm(request.form) if form.validate(): reward = Reward.query.get_or_404(form.rewardid.data) # change this to hide tasks, but leave them in the database? if reward.userid == user.id: db.session.delete(reward) db.session.commit() if form.referpage.data == "redeemed": return redirect(url_for('redeemed')) else: return redirect(url_for('rewards')) else: return redirect(url_for('rewards')) else: return redirect(url_for('front'))