Ejemplo n.º 1
0
def gym_class(id):
    gym_class = gym_class_repository.select(id)
    members = member_repository.select_all()
    attendees = sorted(attendance_repository.select_by_class(gym_class),
                       key=lambda attendance: attendance.member.last_name)

    number_attending = len(attendees)
    class_full = number_attending >= gym_class.location.capacity
    class_peak = gym_class.time >= time(9, 00, 00) and gym_class.time <= time(
        17, 30, 00)

    members_not_attending = []
    for member in members:
        if len(
                attendance_repository.select_by_class_and_member(
                    gym_class, member)) == 0:
            members_not_attending.append(member)

    return render_template(
        '/gym_classes/show.html',
        title=f"{gym_class.class_type} with {gym_class.instructor.name}",
        gym_class=gym_class,
        members=members_not_attending,
        attendees=attendees,
        class_full=class_full,
        number_attending=number_attending,
        class_peak=class_peak)
Ejemplo n.º 2
0
def create():
    gym_class = gym_class_repository.select(request.form["class_id"])
    member = member_repository.select(request.form["member_id"])

    attendance = Attendance(gym_class, member)
    attendance_repository.save(attendance)

    return redirect(f'/classes/{gym_class.id}')
Ejemplo n.º 3
0
def add_booking():
    member_id = request.form["member"]
    gym_class_id = request.form["gym_class"]
    booked_gym_class = gym_class_repository.select(gym_class_id)
    booked_member = member_repository.select(member_id)
    booking = Booking(booked_member, booked_gym_class)
    booking_repository.save(booking)
    return redirect("/bookings")
Ejemplo n.º 4
0
def edit_class(id):
    todays_date = str(date.today())
    gym_class = gym_class_repository.select(id)
    all_instructors = instructor_repository.select_all()
    all_locations = location_repository.select_all()
    return render_template('/gym_classes/edit.html',
                           title="Edit class",
                           gym_class=gym_class,
                           instructors=all_instructors,
                           locations=all_locations,
                           date=todays_date)
Ejemplo n.º 5
0
def destroy_class(id):
    return_to = request.form["return_to"]
    gym_class = gym_class_repository.select(id)
    instructor_id = gym_class.instructor.id

    gym_class_repository.delete(id)

    if return_to == "instructors":
        return redirect(f'/instructors/{instructor_id}')
    else:
        return redirect('/classes')
Ejemplo n.º 6
0
def select(id):
    sql = "SELECT * FROM attendees WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)

    if result is not None:
        gym_class = gym_class_repository.select(result[0]["class_id"])
        member = member_repository.select(result[0]["member_id"])
        attendance = Attendance(gym_class, member, id)

    return attendance
Ejemplo n.º 7
0
def select_all():
    all_attendances = []
    sql = "SELECT * FROM attendees"
    results = run_sql(sql)

    for result in results:
        gym_class = gym_class_repository.select(result["class_id"])
        member = member_repository.select(result["member_id"])
        attendance = Attendance(gym_class, member, id)
        all_attendances.append(attendance)

    return all_attendances
Ejemplo n.º 8
0
def select(id):
    schedule = None
    sql = "SELECT * FROM schedules WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    if result is not None:
        instructor = instructor_repository.select(result['instructor_id'])
        gym_class = gym_class_repository.select(result['class_id'])
        room = room_repository.select(result['room_id'])
        schedule = Schedule(result['class_date'], result['start_time'], result['length_mins'], instructor,
                            gym_class, room, result['id'])
    return schedule
Ejemplo n.º 9
0
def select_all():
    schedules = []
    sql = "SELECT * FROM schedules ORDER BY class_date"
    results = run_sql(sql)
    for row in results:
        instructor = instructor_repository.select(row['instructor_id'])
        gym_class = gym_class_repository.select(row['class_id'])
        room = room_repository.select(row['room_id'])
        schedule = Schedule(row['class_date'], row['start_time'], row['length_mins'], instructor,
                            gym_class, room, row['id'])
        schedules.append(schedule)
    return schedules
Ejemplo n.º 10
0
def select(id):
    booking = None

    sql = "SELECT * FROM bookings WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        member = member_repository.select(result["member_id"])
        gym_class = gym_class_repository.select(result["gym_class_id"])
        booking = Booking(member, gym_class, result["id"])
    return booking
Ejemplo n.º 11
0
def select_all():
    bookings = []

    sql = "SELECT * FROM bookings"
    results = run_sql(sql)

    for row in results:
        member = member_repository.select(row["member_id"])
        gym_class = gym_class_repository.select(row["gym_class_id"])
        booking = Booking(member, gym_class, row["id"])

        bookings.append(booking)
    return bookings
Ejemplo n.º 12
0
def select_by_class(gym_class):
    attendees = []
    sql = "SELECT * FROM attendees WHERE class_id = %s"
    values = [gym_class.id]
    results = run_sql(sql, values)

    for result in results:
        gym_class = gym_class_repository.select(result["class_id"])
        member = member_repository.select(result["member_id"])
        attendance = Attendance(gym_class, member, result["id"])
        attendees.append(attendance)

    return attendees
Ejemplo n.º 13
0
def add_schedule():
    class_date = request.form['class_date']
    start_time = request.form['start_time']
    length_mins = request.form['length_mins']
    instructor_id = request.form['instructor_id']
    class_id = request.form['class_id']
    room_id = request.form['room_id']
    instructor = details_repository.select(instructor_id)
    gym_class = gym_class_repository.select(class_id)
    room = room_repository.select(room_id)
    schedule = Schedule(class_date, start_time, length_mins, instructor,
                        gym_class, room, id)
    schedule_repository.save(schedule)
    return redirect('/schedule')
Ejemplo n.º 14
0
def update_gym_class(id):
    class_type = request.form["gym_class_type"]

    check = gym_class_repository.check_type_exists(class_type)
    if check == False:
        gym_class_repository.new_type(class_type)

    date = request.form["date"]
    time = request.form["time"]
    capacity = request.form["capacity"]
    duration = request.form["duration"]
    edited_class = GymClass(class_type, date, time, capacity, duration, id)
    gym_class_repository.update(edited_class)

    redirect_gym_class = gym_class_repository.select(id)
    redirect_class_types = gym_class_repository.select_types()
    return redirect("/gym_classes/" + id)
Ejemplo n.º 15
0
def select_dates():
    schedules_list = []
    sql = "SELECT * FROM schedules WHERE class_date = %s ORDER BY start_time"
    for index in range(7):
        schedules = []
        values = [date.today() + timedelta(days=index)]
        results = run_sql(sql, values)
        if results is not None:
            for row in results:
                instructor = instructor_repository.select(row['instructor_id'])
                gym_class = gym_class_repository.select(row['class_id'])
                room = room_repository.select(row['room_id'])
                schedule = Schedule(row['class_date'],  row['start_time'], row['length_mins'], instructor,
                                    gym_class, room, row['id'])
                schedules.append(schedule)
        else:
            schedule = None
            schedules.append(schedule)
        schedules_list.append(schedules)
    return schedules_list
Ejemplo n.º 16
0
def edit_gym_class(id):
    gym_class = gym_class_repository.select(id)
    class_types = gym_class_repository.select_types()
    return render_template("gym_classes/edit.html",
                           gym_class=gym_class,
                           class_types=class_types)
Ejemplo n.º 17
0
def show(id):
    gym_class = gym_class_repository.select(id)
    members = booking_repository.members(id)
    return render_template("gym_classes/show.html",
                           gym_class=gym_class,
                           members=members)
Ejemplo n.º 18
0
def see_class(id):
    gym_class = class_repository.select(id)
    return render_template('classes/edit.html', gym_class=gym_class)