def update_class(id):
    instructor = instructor_repository.select(request.form['instructor'])
    location = location_repository.select(request.form["location"])
    updated_class = GymClass(request.form['class_type'], instructor,
                             request.form['date'], request.form['time'],
                             request.form['duration'], location, id)
    gym_class_repository.update(updated_class)
    return redirect(f'/classes/{id}')
def create_class():
    instructor = instructor_repository.select(request.form['instructor'])
    location = location_repository.select(request.form["location"])
    new_gym_class = GymClass(request.form['class_type'], instructor,
                             request.form['date'], request.form['time'],
                             request.form['duration'], location)
    gym_class_repository.save(new_gym_class)
    return redirect('/classes')
def instructor(id):
    instructor = instructor_repository.select(id)
    classes_sorted = sorted(instructor_repository.classes(instructor),
                            key=lambda instructor:
                            (instructor.date, instructor.time))
    return render_template('/instructors/show.html',
                           instructor=instructor,
                           classes=classes_sorted)
def yogaclasses(member):
    sql = """
        SELECT yogaclasses.* FROM yogaclasses
        INNER JOIN bookings
        ON yogaclasses.id = bookings.yogaclass_id
        WHERE member_id = %s
     """
    values = [member.id]
    results = run_sql(sql, values)
    yogaclasses = []
    for row in results:
        instructor = instructor_repository.select(row['instructor_id'])
        yogaclass = YogaClass(row['name'], row['duration'], row['description'],
                              instructor, row['date'], row['time'],
                              row['capacity'], row['active'], row['id'])
        yogaclasses.append(yogaclass)
    return yogaclasses
def update_yogaclass(id):
    name = request.form["name"]
    duration = request.form["duration"]
    description = request.form["description"]
    instructor_id = request.form["instructor"]
    date = request.form["date"]
    time = request.form["time"]
    capacity = request.form["capacity"]
    active = request.form["active"]

    instructor = instructor_repository.select(instructor_id)

    yogaclass = YogaClass(name, duration, description, instructor, date, time,
                          capacity, active, id)

    yogaclass_repository.update(yogaclass)
    return redirect(f'/yogaclasses/{id}')
def create_yogaclass():
    name = request.form["name"]
    duration = request.form["duration"]
    description = request.form["description"]
    instructor_id = request.form["instructor"]
    date = request.form["date"]
    time = request.form["time"]
    capacity = request.form["capacity"]

    instructor = instructor_repository.select(instructor_id)

    yogaclass = YogaClass(name, duration, description, instructor, date, time,
                          capacity)

    yogaclass_repository.save(yogaclass)

    return redirect('/yogaclasses')
def select(id):
    sql = "SELECT * FROM gym_classes WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        instructor = instructor_repository.select(result["instructor_id"])
        location = location_repository.select(result["location_id"])
        class_found = GymClass(result["class_type"], 
        instructor, 
        result["class_date"], 
        result["class_time"], 
        result["duration"], 
        location, 
        result["id"]
    )

    return class_found
def select(id):
    yogaclass = None
    sql = "SELECT * FROM yogaclasses WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        instructor = instructor_repository.select(result['instructor_id'])
        yogaclass = YogaClass(result['name'], 
                              result['duration'],
                              result['description'],
                              instructor,
                              result['date'],
                              result['time'], 
                              result['capacity'], 
                              result['active'],   
                              result['id'])
    return yogaclass
def select_all():
    all_classes = []
    sql = "SELECT * FROM gym_classes ORDER BY class_date, class_time"
    results = run_sql(sql)
    
    for row in results:
        instructor = instructor_repository.select(row["instructor_id"])
        location = location_repository.select(row["location_id"])
        gym_class = GymClass(row["class_type"], 
            instructor, 
            row["class_date"], 
            row["class_time"], 
            row["duration"], 
            location, 
            row["id"]
        )
        all_classes.append(gym_class)
    
    return all_classes
def select_all():
    yogaclasses = []

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

    for row in results:
        instructor = instructor_repository.select(row['instructor_id'])
        yogaclass = YogaClass(row['name'], 
                              row['duration'],
                              row['description'],
                              instructor,
                              row['date'],
                              row['time'], 
                              row['capacity'], 
                              row['active'],   
                              row['id'])
        yogaclasses.append(yogaclass)
    return yogaclasses
Exemple #11
0
def classes(location):
    classes_found = []

    sql = "SELECT * FROM gym_classes WHERE location_id = %s"
    values = [location.id]

    results = run_sql(sql, values)
    for row in results:
        instructor = instructor_repository.select(row["instructor_id"])
        class_found = GymClass(row["class_type"], 
            instructor, 
            row["class_date"], 
            row["class_time"], 
            row["duration"], 
            location, 
            row["id"]
        )
        classes_found.append(class_found)

    return classes_found
def classes(member):
    gym_classes = []

    sql = """
        SELECT gym_classes.* 
        FROM gym_classes 
        INNER JOIN attendees 
        ON attendees.class_id = gym_classes.id 
        WHERE member_id = %s
    """
    values = [member.id]
    results = run_sql(sql, values)

    for row in results:
        instructor = instructor_repository.select(row["instructor_id"])
        location = location_repository.select(row["location_id"])
        gym_class = GymClass(row["class_type"], instructor, row["class_date"],
                             row["class_time"], row["duration"], location,
                             row["id"])
        gym_classes.append(gym_class)

    return gym_classes
def edit_instructor(id):
    instructor = instructor_repository.select(id)
    return render_template('instructors/edit.html',
                           title="Edit Instructor",
                           selected_instructor=instructor)
def edit_instructor(id):
    instructor_found = instructor_repository.select(id)
    return render_template('/instructors/edit.html',
                           instructor=instructor_found)