def create_booking():
    fitness_class = fitness_class_repository.select(
        request.form['fitness_class_id'])
    member = member_repository.select_by_membership_no(
        request.form['membership_no'])
    id = request.form['fitness_class_id']
    class_type = fitness_class.class_type
    date = fitness_class.date
    time = fitness_class.time
    duration = fitness_class.duration
    instructor = fitness_class.instructor
    location = fitness_class.location

    class_participants = fitness_class_repository.get_participants(
        fitness_class)
    for participant in class_participants:
        if participant.id == member.id:
            return redirect('/bookings/member-already-booked')

    if fitness_class.capacity > 0:
        capacity = fitness_class.capacity - 1
        fitness_class = FitnessClass(class_type, date, time, duration,
                                     instructor, capacity, location, id)
        fitness_class_repository.edit(fitness_class)
        new_booking = Booking(member, fitness_class)
        booking_repository.add(new_booking)
        return redirect('/bookings')

    else:
        return redirect('/bookings/class-full')
Exemple #2
0
def update(id):
    trainer = trainer_repo.select(request.form['trainer_id'])
    location = location_repo.select(request.form['location_id'])
    fitness_class = FitnessClass(request.form['title'], trainer, location,
                                 request.form['date'], request.form['time'],
                                 request.form['capacity'], id)
    fitness_class_repo.update(fitness_class)
    return redirect('/classes/' + str(fitness_class.id))
Exemple #3
0
def create_fitness_class():
    title = request.form['title']
    type = request.form['type']
    duration = request.form['duration']
    discription = request.form['discription']
    fitness_class = FitnessClass(title, type, duration, discription)
    fitness_class_repository.save(fitness_class)
    return redirect('/classes')
Exemple #4
0
 def setUp(self):
     self.class_type = self.body_pump = ClassType(
         "Body Pump",
         "Barbell workout to music. Great for building strength and lean muscle!",
         "High", "Moderate")
     self.body_pump_express = FitnessClass(self.class_type, "03/12/2020",
                                           "14:00", "30 minutes",
                                           "Charlotte Anderson", 20,
                                           "Studio 1")
Exemple #5
0
def update__fitness_class(id):
    title = request.form['title']
    type = request.form['type']
    duration = request.form['duration']
    discription = request.form['discription']
    fitness_class = FitnessClass(title, type, duration, discription, id)
    fitness_class_repository.update(fitness_class)
    return render_template("/fitness_classes/show.html",
                           fitness_class=fitness_class)
def select(id):
    fitness_class = None
    sql = "SELECT * FROM fitness_classes WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        fitness_class = FitnessClass(result['title'], result['type'],
                                     result['duration'], result['discription'],
                                     result['id'])
    return fitness_class
def select_all():
    fitness_classes = []
    sql = "SELECT * FROM fitness_classes"
    results = run_sql(sql)
    for result in results:
        fitness_class = FitnessClass(result["title"], result["type"],
                                     result["duration"], result['discription'],
                                     result["id"])
        fitness_classes.append(fitness_class)
    return fitness_classes
def select(id):
    fitness_class = None
    sql = "SELECT * from fitness_classes WHERE id = %s"
    value = [id]
    result = run_sql(sql, value)[0]
    class_type = class_type_repository.select(result['class_type_id'])
    fitness_class = FitnessClass(class_type, result['date'], result['time'],
                                 result['duration'], result['instructor'],
                                 result['capacity'], result['location'],
                                 result['id'])
    return fitness_class
Exemple #9
0
def create_new_fitness():
    try:
        trainer = trainer_repo.select(request.form['trainer_id'])
        location = location_repo.select(request.form['location_id'])
        fitness_class = FitnessClass(request.form['title'], trainer, location,
                                     request.form['date'],
                                     request.form['time'],
                                     request.form['capacity'])
        fitness_class_repo.save(fitness_class)
        return redirect('/classes')
    except:
        return render_template('/errors/missing_data.html'), 405
Exemple #10
0
 def setUp(self):
     self.class_type = self.body_pump = ClassType(
         "Body Pump",
         "Barbell workout to music. Great for building strength and lean muscle!",
         "High", "Moderate")
     self.body_pump_express = FitnessClass(self.class_type, "03/12/2020",
                                           "14:00", "30 minutes",
                                           "Charlotte Anderson", 20,
                                           "Studio 1")
     self.claire = Member("Claire Whittaker", "10 Smith Street",
                          "07783902109", "*****@*****.**", True, 1004)
     self.booking = Booking(self.claire, self.body_pump_express)
Exemple #11
0
def select_all():
    fitness_classes = []
    sql = "SELECT * FROM fitness_classes ORDER BY date ASC, time ASC"
    results = run_sql(sql)

    for row in results:
        trainer = trainer_repo.select(row['trainer_id'])
        location = location_repo.select(row['location_id'])
        fitness_class = FitnessClass(row['title'], trainer, location,
                                     row['date'], row['time'], row['capacity'],
                                     row['id'])
        fitness_classes.append(fitness_class)
    return fitness_classes
def update_fitness_class_details(id):
    class_type = class_type_repository.select(request.form['class_type_id'])
    date = request.form['date']
    time = request.form['time']
    duration = request.form['duration']
    instructor = request.form['instructor']
    location = request.form['location']
    capacity = request.form['capacity']

    updated_class = FitnessClass(class_type, date, time, duration, instructor,
                                 capacity, location, id)
    fitness_class_repository.edit(updated_class)
    return redirect('/fitness-classes')
Exemple #13
0
def select(id):
    fitness_class = None
    sql = "SELECT * FROM fitness_classes WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        trainer = trainer_repo.select(result['trainer_id'])
        location = location_repo.select(result['location_id'])
        fitness_class = FitnessClass(result['title'], trainer, location,
                                     result['date'], result['time'],
                                     result['capacity'], result['id'])
    return fitness_class
def select_all():
    all_fitness_classes = []
    sql = "SELECT * FROM fitness_classes ORDER BY date ASC, time ASC"
    results = run_sql(sql)
    # pdb.set_trace()
    for result in results:
        class_type = class_type_repository.select(result['class_type_id'])
        fitness_class = FitnessClass(class_type, result['date'],
                                     result['time'], result['duration'],
                                     result['instructor'], result['capacity'],
                                     result['location'], result['id'])
        all_fitness_classes.append(fitness_class)

    return all_fitness_classes
def find_classes_by_class_type(class_type):
    found_classes = []
    sql = "SELECT * from fitness_classes WHERE class_type_id = %s"
    value = [class_type.id]
    results = run_sql(sql, value)

    for result in results:
        found_class = FitnessClass(class_type, result['date'], result['time'],
                                   result['duration'], result['instructor'],
                                   result['capacity'], result['location'],
                                   result['id'])
        found_classes.append(found_class)

    return found_classes
def create_fitness_class():
    class_type = class_type_repository.select(request.form['class_type_id'])
    date = request.form['date']
    time = request.form['time']
    duration = request.form['duration']
    instructor = request.form['instructor']
    location = request.form['location']
    capacity = request.form['capacity']

    # print("🐰" + class_type.name + "🐰")

    new_class = FitnessClass(class_type, date, time, duration, instructor,
                             capacity, location)
    fitness_class_repository.add(new_class)
    return redirect('/fitness-classes')
def find_classes_by_date(date):
    found_classes = []
    sql = "SELECT * from fitness_classes WHERE date = %s"
    value = [date]
    results = run_sql(sql, value)

    for result in results:
        class_type = class_type_repository.select(result['class_type_id'])
        found_class = FitnessClass(class_type, result['date'], result['time'],
                                   result['duration'], result['instructor'],
                                   result['capacity'], result['location'],
                                   result['id'])
        found_classes.append(found_class)

    return found_classes
def bookings(member):
    fitness_classes = []
    bookings = []

    sql = "SELECT fitness_class_member_bookings.id AS booking_id, fitness_classes.* FROM fitness_classes INNER JOIN fitness_class_member_bookings ON fitness_class_member_bookings.fitness_class_id = fitness_classes.id WHERE member_id = %s"
    values = [member.id]
    results = run_sql(sql, values)
    for row in results:
        fitness_class = FitnessClass(row['title'], row['type'],
                                     row['duration'], row['discription'],
                                     row['id'])
        fitness_classes.append(fitness_class)
        bookings.append(row['booking_id'])

    return (fitness_classes, bookings)
def delete_booking(id):
    booking = booking_repository.select(id)
    fitness_class_id = booking.fitness_class.id
    fitness_class = fitness_class_repository.select(booking.fitness_class.id)
    class_type = fitness_class.class_type
    date = fitness_class.date
    time = fitness_class.time
    duration = fitness_class.duration
    instructor = fitness_class.instructor
    location = fitness_class.location
    capacity = fitness_class.capacity + 1

    fitness_class = FitnessClass(class_type, date, time, duration, instructor,
                                 capacity, location, fitness_class_id)
    fitness_class_repository.edit(fitness_class)

    booking_repository.delete(id)
    return redirect('/bookings')
Exemple #20
0
def get_booked_classes(member):
    class_list = []
    sql = """SELECT fitness_classes.*
                FROM fitness_classes
                INNER JOIN bookings ON fitness_classes.id = bookings.fitness_class_id
                INNER JOIN members ON members.id = bookings.member_id
                WHERE members.id = %s"""

    values = [member.id]
    sql_results = run_sql(sql, values)

    for result in sql_results:
        class_type = class_type_repository.select(result['class_type_id'])
        fitness_class = FitnessClass(class_type, result['date'],
                                     result['time'], result['duration'],
                                     result['instructor'], result['capacity'],
                                     result['location'], result['id'])
        class_list.append(fitness_class)

    return class_list
Exemple #21
0
def fitness_classes(member):
    values = [member.id]
    sql = """
        SELECT fitness_classes.* FROM fitness_classes 
        INNER JOIN attendance 
        ON fitness_classes.id = attendance.fitness_class_id
        WHERE member_id = %s
        ORDER BY 
        date ASC, 
        time ASC
    """
    results = run_sql(sql, values)

    fitness_classes = []
    for row in results:
        trainer = trainer_repo.select(row['trainer_id'])
        location = location_repo.select(row['location_id'])
        fitness_class = FitnessClass(row['title'], trainer, location,
                                     row['date'], row['time'], row['capacity'],
                                     row['id'])
        fitness_classes.append(fitness_class)
    return fitness_classes
trainer_repo.save(trainer2)
trainer3 = Trainer('Jamie', 'Gray')
trainer_repo.save(trainer3)

member1 = Member('Shaun', 'Hodge', 'standard', '2021/01/10', 'EH5 3RU', '07596685374', '*****@*****.**')
member_repo.save(member1)
member2 = Member('Jade', 'Breslin', 'premium', '2020/08/13', 'EH12 1SU', '07759244212', '*****@*****.**')
member_repo.save(member2)
member3 = Member('Lucy', 'Atkinson', 'premium', '2019/10/25', 'EH2 6SR', '07321844372', '*****@*****.**')
member_repo.save(member3)
member4 = Member('James', 'Holden', 'standard', '2019/06/13', 'EH7 9DE', '07538472658', '*****@*****.**')
member_repo.save(member4)
member5 = Member('Gary', 'McDonald', 'standard', '2021/01/14', 'EH15 7ST', '07695844449', '*****@*****.**')
member_repo.save(member5)

fitness_class1 = FitnessClass('Body Attack', trainer2, location1, '2021/03/10', '13:00', 20)
fitness_class_repo.save(fitness_class1)
fitness_class2 = FitnessClass('HIIT', trainer1, location3, '2021/03/10', '17:00', 30)
fitness_class_repo.save(fitness_class2)
fitness_class3 = FitnessClass('Zumba', trainer1, location1, '2021/03/10', '18:15', 35)
fitness_class_repo.save(fitness_class3)
fitness_class4 = FitnessClass('Yoga', trainer2, location2, '2021/03/10', '07:00', 20)
fitness_class_repo.save(fitness_class4)

attendance1 = Attendance(fitness_class1, member2)
attendance_repo.save(attendance1)
attendance2 = Attendance(fitness_class1, member3)
attendance_repo.save(attendance2)
attendance3 = Attendance(fitness_class1, member4)
attendance_repo.save(attendance3)
attendance4 = Attendance(fitness_class2, member2)
Exemple #23
0
    "Body Pump", "Barbell workout to music. Great for building lean muscle!",
    "High", "Moderate")
class_type_repository.add(body_pump)

body_balance = ClassType(
    "Body Balance", "A mix of yoga, tai chi and pilates. Great for mobility",
    "Low", "Low")
class_type_repository.add(body_balance)

spin = ClassType(
    "Spin",
    "Calorie-burning workout to music on an exercise bike. Gets your heart rate up!",
    "High", "Medium")
class_type_repository.add(spin)

body_pump_express = FitnessClass(body_pump, "03/12/2020", "14:00", 30,
                                 "Charlotte Anderson", 20, "Studio 1")
fitness_class_repository.add(body_pump_express)

body_balance_am = FitnessClass(body_balance, "04/12/2020", "10:00", 55,
                               "Madeleine Johnson", 8, "Studio 2")
fitness_class_repository.add(body_balance_am)

body_balance_am = FitnessClass(body_balance, "05/12/2020", "18:00", 45,
                               "Anna Murray", 15, "Studio 1",
                               body_balance_am.id)
fitness_class_repository.edit(body_balance_am)

booking_1 = Booking(angela, body_pump_express)
booking_repository.add(booking_1)

booking_2 = Booking(claire, body_balance_am)
 def setUp(self):
     self.fitness_class = FitnessClass("Spin", "Cardio", 45)
fitness_class_repository.delete_all()

member_1 = Member("Bob", "Anders", "1980-01-10", 1, "Standard")
member_repository.save(member_1)

member_2 = Member("Clare", "Bower", "1985-02-15", 2, "Standard")
member_repository.save(member_2)

member_3 = Member("Jim", "Adler", "1970-05-20", 3, "Premium")
member_repository.save(member_3)

member_4 = Member("Mark", "Bishop", "1990-10-19", 4, "Premium")
member_repository.save(member_4)

class_1 = FitnessClass(
    "Yoga", "Conditioning", 45,
    "A spiritual discipline which includes breath control, meditation, and the adoption of specific postures to aid health and relaxation."
)
fitness_class_repository.save(class_1)

class_2 = FitnessClass(
    "Lunchtime Pilates", "Conditioning", 30,
    "A shorter version of our popular exercise class which helps build strength from the inside out, rebalancing the body and bringing it into alignment. mins."
)
fitness_class_repository.save(class_2)

class_3 = FitnessClass(
    "Pilates", "Conditioning", 60,
    "A popular exercise class which helps build strength from the inside out, rebalancing the body and bringing it into alignment. Pilates helps to reshape your body, which will become leaner and more toned as a result of undertaking this class. It will also improve your posture, achieving the perfect balance between strength and flexibility. mins."
)
fitness_class_repository.save(class_3)