def update(id): original_member = member_repo.select(id) updated_member = Member( request.form['first_name'], request.form['last_name'], request.form['membership'], original_member.join_date, request.form['post_code'], request.form['phone_number'], request.form['email'], id) member_repo.update(updated_member) return redirect('/members/' + str(updated_member.id))
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 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 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))
def edit(id): found_member = member_repo.select(id) return render_template('/members/edit.html', member=found_member)
def show(id): found_member = member_repo.select(id) found_fitness_classes = member_repo.fitness_classes(found_member) return render_template('/members/show.html', member=found_member, fitness_classes=found_fitness_classes)