Exemple #1
0
def delete(programme_id):
    programme = Programme.get(id=programme_id)

    if not programme:
        abort(404)

    programme.delete()
    db.commit()

    return '', 204
Exemple #2
0
def show_programme_results(programme_id):
    # This will serialize our data
    schema = ProgrammeSchema()
    # This gets a programme by ID
    programme = Programme.get(id=programme_id)

    # If we can't find a programme, send a 404 response
    if not programme:
        abort(404)

    # otherwise, send back the programme data as JSON
    return schema.dumps(programme)
Exemple #3
0
def delete_exercise_item(programme_id, item_id):
    schema = ProgrammeSchema()
    programme = Programme.get(id=programme_id)  #get/set programme id
    exercise_item = ExerciseItem.get(id=item_id)  #get/set specific entry id

    if not exercise_item:
        abort(404)

    exercise_item.delete()  #delete the specific entry
    db.commit()

    return schema.dumps(programme)
Exemple #4
0
def show_exercise_items(programme_id):

    schema = ExerciseItemSchema(many=True)
    day = request.args.get(
        'day')  #set day variable to hold the day from the request query string
    programme = Programme.get(
        id=programme_id)  #set programme variale to hold programme_id
    exercise_items = ExerciseItem.select(
        lambda item: item.day == day and item.programme == programme)
    # set exercise_items to be all the exercise items for the current day, from the current programme

    return schema.dumps(exercise_items)
Exemple #5
0
def update(programme_id):
    schema = ProgrammeSchema()  #get/set schema from ProgrammeSchema
    programme = Programme.get(id=programme_id)  # get/set programme

    if not programme:
        abort(404)

    try:
        data = schema.load(
            request.get_json())  #load the updated info onto data
        programme.set(**data)  # add all the data to the programme
        db.commit()
    except ValidationError as err:
        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422

    return schema.dumps(programme)
Exemple #6
0
def create_exercise_item(programme_id):
    schema = ProgrammeSchema()
    exercise_item_schema = ExerciseItemSchema()
    programme = Programme.get(id=programme_id)

    if not programme:
        abort(404)

    try:
        data = exercise_item_schema.load(request.get_json())
        ExerciseItem(**data, programme=programme)
        db.commit()
    except ValidationError as err:
        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422

    return schema.dumps(programme)
Exemple #7
0
def create():
    # This will deserialize the JSON from insomnia
    schema = ProgrammeSchema()

    try:
        # attempt to convert the JSON into a dict
        data = schema.load(request.get_json())
        # Use that to create a programme object
        programme = Programme(name=data['name'], user=g.current_user)
        db.commit()

    except ValidationError as err:
        # if the validation fails, send back a 422 response
        return jsonify({
            'message': 'Validation failed',
            'errors': err.messages
        }), 422

    # otherwise, send back the programme data as JSON
    return schema.dumps(programme), 201
Exemple #8
0
    #legs
    squat = Exercise(name="Squat")
    leg_press = Exercise(name="Leg Press")
    leg_extension = Exercise(name="Leg Extension")
    leg_curl = Exercise(name="Leg Curl")
    calf_raise = Exercise(name="Calf Raise")

    #back
    lat_pulldown = Exercise(name="Lat Pulldown")
    cable_seated_row = Exercise(name="Cable Seated Row")

    #full body
    dead_lift = Exercise(name="Dead Lift")

    # seed programmes •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
    summer = Programme(name='Summer Programme', user=adam_p)
    winter = Programme(name='Winter Programme', user=adam_p)

    # •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

    ExerciseItem(exercise=dumbbell_fly,
                 day='Monday',
                 weights=[{
                     'value': 20,
                     'date': '2018-12-12'
                 }, {
                     'value': 20,
                     'date': '2019-01-15'
                 }, {
                     'value': 18,
                     'date': '2019-01-17'
Exemple #9
0
def index():
    schema = ProgrammeSchema(many=True)
    programmes = Programme.select()  # get all the programmes
    return schema.dumps(programmes)  # `schema.dumps` converts the list to JSON