Пример #1
0
def goals():
    print(f"REQ: {request.form}")
    if request.method == 'POST':
        result = request.form.copy()
        result['user_id'] = session['USER_ID']
        new_goal = Goal()
        new_goal.populate(result)
        db.session.add(new_goal)
        db.session.commit()

    stats = get_goal_stats(session['USER_ID'])
    print(f"GOAL: {stats}")
    return render_template('goals.html', stats=stats, users=get_users())
Пример #2
0
def goals():
    if request.method == 'POST':
        new_goal = Goal()
        new_goal.populate(request.form)
        db.session.add(new_goal)
        db.session.commit()
        return "True"
    elif request.method == 'GET':
        user_id = request.args.get('user_id')
        action = request.args.get('type')
        recent_goal = Goal.query.filter_by(user_id=user_id).order_by(
            Goal.set_time)[::-1]
        if not recent_goal:
            return "No goals found"
        recent_goal = recent_goal[0]
        print(recent_goal)
        if action == "steps":
            return str(recent_goal.steps)
        elif action == "distance":
            return str(recent_goal.distance)
        return "Incorrect parameters"