def update_workout(id):
    # Form data
    name        = request.form['name']
    category    = request.form['category']
    capacity    = request.form['capacity']
    # Format date
    date        = request.form['date']
    # Split the date into a list
    split_date = date.split('-')
    # create a new date object
    date = datetime.date(int(split_date[0]), int(split_date[1]), int(split_date[2]))
    
    # Format time
    start_time  = request.form['start_time']
    # Split the time into a list
    split_start_time = start_time.split(':')
    # create new time object
    start_time = datetime.time(int(split_start_time[0]), int(split_start_time[1]))

    # Create new Workout object
    workout = Workout(name, category, date, start_time, capacity, id=id)
    # Update in db
    workout_repository.update(workout)
    # Redirect
    return redirect('/workouts')
Esempio n. 2
0
def update_workout(id):
    name = request.form['name']
    type = request.form['type']
    duration = request.form['duration']
    date = request.form['date']
    capacity = request.form['capacity']
    workout = Workout(name, type, duration, date, capacity, id)
    workout_repository.update(workout)
    return redirect('/workouts')
def update_workout(id):
    activity_id = request.form['activity_id']
    day = request.form['day']
    time = request.form['time']
    capacity = request.form['capacity']

    activity = activity_repository.select(activity_id)

    workout = Workout(activity, day, time, capacity, id)
    workout_repository.update(workout)
    return redirect("/workouts")
Esempio n. 4
0
def remove_booking(id):
    # Select workout from booking
    booking = booking_repository.select(id)
    workout_id = booking.workout.id
    workout = workout_repository.select(workout_id)
    # Delete booking
    booking_repository.delete(id)
    # Decrease booked in workout and updte db
    workout.decrease_booked()
    workout_repository.update(workout)
    # Flash success message
    flash(f"Removed {booking.member.first_name} from {booking.workout.name}!", "success")
    # Redirect
    return redirect('/bookings')
Esempio n. 5
0
def create_booking():
    # Get data from form
    member_id   = request.form['member']
    workout_id  = request.form['workout']
    # Select existing member and workout
    member = member_repository.select(member_id)
    workout = workout_repository.select(workout_id)
    # Create new booking object
    booking = Booking(member, workout)
    # Save to db
    booking_repository.save(booking)
    # Increment booking to workout and update workout
    booking.workout.increment_booked()
    workout_repository.update(workout)
    # Flash success message
    flash(f"{booking.member.first_name} was added to {booking.workout.name}!", "success")
    # Redirect
    return redirect('/bookings')
Esempio n. 6
0
# booking_repository.delete_all()

member_1 = Member("Dario", "Cologna", "male", 34)
member_repository.save(member_1)
member_2 = Member("Guido", "Van Rossum", "male", 64)
member_repository.save(member_2)
workout_1 = Workout("Just Skate", "freestyle", datetime.date(2020, 12, 16),
                    datetime.time(6, 15), 2)
workout_repository.save(workout_1)
workout_2 = Workout("Double Poling", "classic", datetime.date(2020, 12, 10),
                    datetime.time(10, 30), 3)
workout_repository.save(workout_2)
booking_1 = Booking(member_1, workout_1)
booking_repository.save(booking_1)
workout_1.increment_booked()
workout_repository.update(workout_1)

# booking_2 = Booking(member_1, workout_2)
# booking_repository.save(booking_2)
# booking_3 = Booking(member_2, workout_1)
# booking_repository.save(booking_3)
# id = booking_1.id
# booking = booking_repository.select(id)
# workout_id = booking.workout.id
# workout = workout_repository.select(workout_id)
# # Decrease booked in workout
# workout.decrease_booked()
# workout_repository.update(workout)
# # Delete booking
# booking_repository.delete(id)