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')
def select(id): sql = "SELECT * FROM bookings WHERE id = %s" value = [id] result = run_sql(sql, value)[0] member = member_repository.select(result['member_id']) fitness_class = fitness_class_repository.select(result['fitness_class_id']) booking = Booking(member, fitness_class, result['id']) return booking
def bookings_members(id): fitness_class = fitness_class_repository.select(id) members = booking_repository.get_fitness_class_bookings(fitness_class)[0] bookings = booking_repository.get_fitness_class_bookings(fitness_class)[1] return render_template("/fitness_classes/bookings.html", bookings=bookings, fitness_class=fitness_class, members=members)
def select_all(): sql = "SELECT * FROM bookings" results = run_sql(sql) all_bookings = [] for result in results: member = member_repository.select(result['member_id']) fitness_class = fitness_class_repository.select(result['fitness_class_id']) booking = Booking(member, fitness_class, result['id']) all_bookings.append(booking) return all_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')
def view_class_description(id): fitness_class = fitness_class_repository.select(id) return render_template("fitness_classes/class_description.html", fitness_class=fitness_class)
def edit_fitness_class_details(id): class_types = class_type_repository.select_all() fitness_class = fitness_class_repository.select(id) return render_template("fitness_classes/edit.html", fitness_class=fitness_class, class_types=class_types)
def display_participants(id): fitness_class = fitness_class_repository.select(id) participant_list = fitness_class_repository.get_participants(fitness_class) return render_template("fitness_classes/participant_list.html", participant_list=participant_list)
def edit_fitness_class(id): fitness_class = fitness_class_repository.select(id) class_types = type_repository.select_all() return render_template('fitness_classes/edit.html', fitness_class=fitness_class, class_types=class_types)
def show_fitness_class(id): fitness_class = fitness_class_repository.select(id) return render_template("fitness_classes/show.html", fitness_class=fitness_class)