Esempio n. 1
0
def select(id):
    sql = "SELECT * FROM bookings WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    member = member_repository.select(result["member_id"])
    session = session_repository.select(result["session_id"])
    booking = Booking(member, session, result["id"])
    return booking
Esempio n. 2
0
def add_booking():
    member_id = request.form["member_id"]
    session_id = request.form["session_id"]
    member = member_repository.select(member_id)
    session = session_repository.select(session_id)
    booking = Booking(member, session)
    booking_repository.save(booking)
    return redirect("/bookings")
Esempio n. 3
0
def create_task():
    member_id = request.form['member_id']
    session_id = request.form['session_id']
    member = member_repository.select(member_id)
    session = session_repository.select(session_id)
    booking = Booking(member, session)
    booking_repository.save(booking)
    return redirect('/bookings')
Esempio n. 4
0
def select_all():
    bookings=[]
    
    sql = "SELECT * FROM bookings ORDER BY id DESC"
    results = run_sql(sql)
    
    for row in results:
        member = member_repository.select(row["member_id"])
        session = session_repository.select(row["session_id"])
        booking = Booking(member, session, row["id"])
        bookings.append(booking)
    return bookings
Esempio n. 5
0
def select_all():
    bookings = []

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

    for row in results:
        member = member_repository.select(row['member_id'])
        session = session_repository.select(row['session_id'])
        booking = Booking(member, session, row['id'])
        bookings.append(booking)
    return bookings
Esempio n. 6
0
def update_session(id):
    if request.method == 'POST':
        name = request.form["name"]
        description = request.form["description"]
        upcoming = request.form["upcoming"]
        capacity = request.form["capacity"]
        offpeak = request.form["offpeak"]
        session = Session(name, description, upcoming, capacity, offpeak, id)
        session_repository.update(session)

        if int(capacity) > session_repository.how_many_members(id):

            booked_member_id = request.form["booked_member_id"]
            if booked_member_id != "0":
                booking = Booking(member_repository.select(booked_member_id),
                                  session_repository.select(id))
                booking_repository.save(booking)

            return redirect("/sessions")

        return redirect("/sessions")

    else:
        session = session_repository.select(id)
        booked_members = session_repository.select_booked_members(id)
        if session.offpeak == False:
            members = member_repository.select_all_premium_active_members()
        else:
            members = member_repository.select_active()

        capacity = session_repository.select(id)
        spaces_taken = session_repository.how_many_members(id)

        if int(capacity.capacity) <= spaces_taken:
            flash(' This class is full, no more bookings available!!!')
        return render_template("/sessions/edit.html",
                               id=id,
                               session=session,
                               booked_members=booked_members,
                               members=members)
Esempio n. 7
0
def edit_session(id):
    session = session_repository.select(id)
    return render_template("/sessions/edit.html", session=session)
Esempio n. 8
0
def show(id):
    session = session_repository.select(id)
    members = session_repository.members(session)
    return render_template("/sessions/show.html",
                           session=session,
                           members=members)