Example #1
0
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'))
Example #2
0
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'))
Example #3
0
def rewardupdate():
    if 'userid' in session:
        user = User.query.get_or_404(session['userid'])
        if request.method == 'POST':
            updateform = RewardUpdateForm(request.form)
            if updateform.validate():
                reward = Reward.query.get_or_404(updateform.rewardid.data)
                if reward.userid == user.id:
                    # update fields
                    reward.title = updateform.title.data
                    reward.cost = updateform.cost.data
                    #task.datedue = updateform.datedue.data
                    db.session.commit()
                return redirect(url_for('rewards'))
            else:
                rewards = user.rewards.filter(
                    Reward.redeemed == False).order_by(desc(
                        Reward.dateadded)).all()
                return render_template('rewards.html',
                                       username=user.username,
                                       points=user.points,
                                       rewards=rewards,
                                       form=RewardForm(),
                                       idform=RewardIdForm(),
                                       updateform=updateform,
                                       containerclass="rewardcontainer")
        else:
            return redirect(url_for('rewards'))
    else:
        return redirect(url_for('front'))
Example #4
0
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'))
Example #5
0
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'))
Example #6
0
def rewards():
    if 'userid' in session:
        user = User.query.get_or_404(session['userid'])

        if request.method == 'POST':
            form = RewardForm(request.form)
            if form.validate():
                print form.cost.data
                newreward = Reward(form.title.data, user, None, form.cost.data)
                db.session.add(newreward)
                db.session.commit()
                return redirect(url_for('rewards'))
            else:
                rewards = user.rewards.filter(
                    Reward.redeemed == False).order_by(desc(
                        Reward.dateadded)).all()
                return render_template('rewards.html',
                                       username=user.username,
                                       points=user.points,
                                       rewards=rewards,
                                       form=form,
                                       idform=RewardIdForm(),
                                       updateform=RewardUpdateForm(),
                                       containerclass="rewardcontainer")

        else:
            rewards = user.rewards.filter(Reward.redeemed == False).order_by(
                desc(Reward.dateadded)).all()
            return render_template('rewards.html',
                                   username=user.username,
                                   points=user.points,
                                   rewards=rewards,
                                   form=RewardForm(),
                                   idform=RewardIdForm(),
                                   updateform=RewardUpdateForm(),
                                   containerclass="rewardcontainer")
    # if no session, display default home page. TODO: convert to splash page
    else:
        return redirect(url_for('front'))
Example #7
0
def redeemed():
    if 'userid' in session:
        user = User.query.get_or_404(session['userid'])
        redeemed = user.rewards.filter(Reward.redeemed == True).order_by(
            desc(Reward.dateredeemed)).all()
        return render_template('redeemed.html',
                               username=user.username,
                               points=user.points,
                               redeemed=redeemed,
                               idform=RewardIdForm(),
                               containerclass="rewardcontainer")
    # if no session, display default home page. TODO: convert to splash page
    else:
        return redirect(url_for('front'))