def edit(id): found_fitness_class = fitness_class_repo.select(id) all_trainers = trainer_repo.select_all() all_locations = location_repo.select_all() return render_template('/fitness_classes/edit.html', fitness_class=found_fitness_class, trainers=all_trainers, locations=all_locations)
def select_by_fitness_class(fitness_class): sql = "SELECT * FROM attendance WHERE fitness_class_id = %s" values = [fitness_class.id] results = run_sql(sql, values) attendance_list = [] for row in results: member = member_repo.select(row['member_id']) fitness_class = fitness_class_repo.select(row['fitness_class_id']) attendance = Attendance(fitness_class, member, row['id']) attendance_list.append(attendance) return attendance_list
def select(id): attendance = None sql = "SELECT * FROM attendance WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: member = member_repo.select(result['member_id']) fitness_class = fitness_class_repo.select(result['fitness_class_id']) attendance = Attendance(fitness_class, member, result['id']) return attendance
def select_all(): attendance_list = [] sql = "SELECT * FROM attendance" results = run_sql(sql) for row in results: member = member_repo.select(row['member_id']) fitness_class = fitness_class_repo.select(row['fitness_class_id']) attendance = Attendance(fitness_class, member, row['id']) attendance_list.append(attendance) return attendance_list
def sign_up_member_form(id): found_fitness_class = fitness_class_repo.select(id) if (found_fitness_class.time.hour >= 17 and found_fitness_class.time.hour < 19) or (found_fitness_class.time.hour >= 7 and found_fitness_class.time.hour < 9): not_attending = fitness_class_repo.not_members_premium( found_fitness_class) else: not_attending = fitness_class_repo.not_members(found_fitness_class) return render_template('/attendances/new.html', fitness_class=found_fitness_class, members=not_attending)
def update(): found_member = member_repo.select(request.form['member_id']) found_fitness_class = fitness_class_repo.select( request.form['fitness_class_id']) # verify there is availability on the class if for some reason the user manages to get this far calc_availability = found_fitness_class.capacity - len( attendance_repo.select_by_fitness_class(found_fitness_class)) if calc_availability > 0: attendance = Attendance(found_fitness_class, found_member) attendance_repo.save(attendance) else: return render_template('/errors/405.html'), 405 return redirect('/classes/' + str(found_fitness_class.id))
def show(id): found_fitness_class = fitness_class_repo.select(id) found_members = fitness_class_repo.members(found_fitness_class) all_members = member_repo.select_all() # availability needs to be calculated to verify where or not the add member to class button is to show calc_availability = found_fitness_class.capacity - len( attendance_repo.select_by_fitness_class(found_fitness_class)) # check if any members can be added current_attendances = attendance_repo.select_by_fitness_class( found_fitness_class) members_to_add = len(current_attendances) != len(all_members) return render_template('/fitness_classes/show.html', members=found_members, fitness_class=found_fitness_class, availability=calc_availability, members_to_add=members_to_add)
def delete(id): member = member_repo.select(request.form['member_id']) fitness_class = fitness_class_repo.select(request.form['fitness_class_id']) attendance_repo.delete_by_fitness_class_and_member(fitness_class, member) return redirect('/classes/' + str(fitness_class.id))