def test_getSingleWorkoutByName(self):

        user = User(username="******", password="******", email="*****@*****.**")
        db.session.add(user)
        db.session.commit()

        w1 = Workout(user_id=user.id, name="Work Out 1", level="Easy")
        w2 = Workout(user_id=user.id, name="Work Out 2", level="Easy")
        db.session.add(w1)
        db.session.add(w2)
        db.session.commit()

        workoutName1 = Workout.find_single_workout_by_name_("Work Out 1")
        workoutName2 = Workout.find_single_workout_by_name_("Work Out 2")

        assert workoutName2.name == w2.name
        assert workoutName1.name == w1.name
Exemplo n.º 2
0
def get_workout_page():
    givenWorkoutName = request.args.get('name')
    
    workout = Workout.find_single_workout_by_name_(givenWorkoutName)
    if workout != None:
        workoutNameFound = Markup(workout.name)
        return render_template("workouts/workout.html", creatingNewWorkout = False, workoutName = workoutNameFound)
    else:
        return render_template("workouts/workout.html", creatingNewWorkout = True)
Exemplo n.º 3
0
def check_if_name_is_unique():
    workoutName = request.args.get('name', '')
    workout = Workout.find_single_workout_by_name_(workoutName)
    
    if workout is None:
        result = {"Result":"True"}
        return jsonify(result)
    else:
        result = {"Result":"False"}
        return jsonify(result)
def submit_workout_history():
    wName = request.form['wName']
    date = request.form['date']
    desc = request.form['desc']
    user = User.find_by_username(request.form['user'])
    workout = Workout.find_single_workout_by_name_(wName)
    if(workout == None):
        return jsonify(result="errorName", content=" The workout name you have entered may not exist. Please double check the spelling of the workout name. Thank you")
    if(date == ""):
        return jsonify(result="errorDate", content=" Please enter the date and time of the completed workout")
    
    wh = WorkoutHistory(user.id, workout.id, datetime.strptime(date, "%m/%d/%Y %I:%M:%S %p"), desc, True)
    WorkoutHistory.save_to_db(wh)
       
    feed = "comleted "+wName+" on "+date+" - "+desc;
    user.add_newsfeed(feed);
    return jsonify(result="success");
Exemplo n.º 5
0
def get_single_workout():
    workoutName = request.args.get('name')
    
    if workoutName is None:
        id = request.args.get('id')
        workout = Workout.find_single_workout_by_id(id)
    else:
        workout = Workout.find_single_workout_by_name_(workoutName)
    if workout != None:
        workoutData = workout.to_hash()
        exercises = Exercise.find_all_by_workOutId(workout.id)
        
        exerciseData = []
        for exercise in exercises:
            exerciseData.append(exercise.to_hash())
        
        returnVal = {"Result": "Success", "workoutData": workoutData,"exerciseData": exerciseData}
        return  jsonify(returnVal)
    else:
        returnVal = {"Result": "Failure"}
        return  jsonify(returnVal)
Exemplo n.º 6
0
def edit_workout():
    exercises = request.data
    
    if(len(exercises) == 0):
        result = {"Result":"Failure"}
        return jsonify(result)
    
    jsonExercises = json.loads(exercises)
    
    if jsonExercises == None:
        result = {"Result":"Failure"}
        return jsonify(result)
    else:
        if len(jsonExercises) == 0:
            result = {"Result":"Failure"}
            return jsonify(result)
        else:
            name = jsonExercises['name']
            description = jsonExercises['description']
            level = jsonExercises['level']

            isPublic = jsonExercises['isPublic']
            if isPublic == 'true':
                isPublic = True
            else:
                isPublic = False
            isLikeable = jsonExercises['isLikeable']
            if isLikeable == 'true':
                isLikeable = True
            else:
                isLikeable = False
            isCommentable = jsonExercises['isCommentable']
            if isCommentable == 'true':
                isCommentable = True
            else:
                isCommentable = False
            
            currentWorkout = Workout.find_single_workout_by_name_(name)
            currentWorkout.level = level
            currentWorkout.is_public = isPublic
            currentWorkout.is_likeable = isLikeable
            currentWorkout.is_commentable = isCommentable
            currentWorkout.description = description
            Workout.update_workout_info(currentWorkout)
            
            for exercise in jsonExercises['exercises']:
                order = exercise['order']
                type = exercise['type']
                unit = exercise['unit']
                exerciseTag = ExerciseTag.find_by_name(type)
                if exerciseTag is None:
                    exerciseTag = ExerciseTag(type, unit)
                    ExerciseTag.save_to_db(exerciseTag)
                amount = exercise['amount']
                additionalInfo = exercise['additionalInfo']
                
                currentExercise = Exercise.find_by_workOutId_and_order(currentWorkout.id, order)
                if currentExercise is None:
                    newExercise = Exercise(currentWorkout.id, exerciseTag.id, order, amount, additionalInfo)
                    Exercise.save_to_db(newExercise)
                else:
                    currentExercise.eTagId = exerciseTag.id
                    currentExercise.amount = amount
                    currentExercise.additionalInfo = additionalInfo
                    Exercise.update_exercise_info(currentExercise)
            
            result = {"Result":"Success"}
            return jsonify(result)