コード例 #1
0
def select(id):
    repair = None
    sql = "SELECT * FROM repairs WHERE id = %s ORDER BY repair_date DESC"
    values = [id]  # a list is supplied to run_sql

    result = run_sql(sql, values)[0]  # ensure only one row is returned.

    if result is not None:
        # using mechanic_id from repairs, retrieve mechanic object
        mechanic = mechanic_repository.select(result['mechanic_id'])

        # using car_id from repairs, retrieve car object
        car = car_repository.select(result['car_id'])

        # create Repair object, assign to variable 'repair'
        repair = Repair(result['repair_date'], result['details'], mechanic,
                        car, result['id'])

    return repair
コード例 #2
0
def update_repair(id):

    repair_date = request.form['repair_date']
    details = request.form['details']

    machanic_id = request.form["mechanic_id"]
    mechanic = mechanic_repository.select(machanic_id)

    car_id = request.form["car_id"]
    car = car_repository.select(car_id)

    # create repair object
    repair = Repair(repair_date, details, mechanic, car, id)

    # update repair on database
    repair_repository.update(repair)

    # send control back to repairs page
    return redirect("/repairs")
コード例 #3
0
def create_repair():
    repair_date = request.form['repair_date']
    details = request.form['details']

    # 'extract' mechanic_id and request retrieval of its class
    mechanic_id = request.form['mechanic_id']
    mechanic = mechanic_repository.select(mechanic_id)

    # 'extract' car_id and request retrieval of its class
    car_id = request.form['car_id']
    car = car_repository.select(car_id)

    # create repair object
    repair = Repair(repair_date, details, mechanic, car)

    # send request to save repair to database
    repair_repository.save(repair)

    # return to reapirs webpage
    return redirect('/repairs')
コード例 #4
0
def search(search_string):
    repairs = []

    if len(search_string) > 0:
        sql = "SELECT * FROM repairs WHERE UPPER(details) LIKE UPPER(%s) ORDER BY repair_date DESC"
        new_search_string = '%' + search_string + '%'
        values = [new_search_string]

        results = run_sql(sql, values)

        for row in results:
            mechanic = mechanic_repository.select(row['mechanic_id'])
            car = car_repository.select(row['car_id'])

            # create Repair object, assign to variable 'repair'
            repair = Repair(row['repair_date'], row['details'], mechanic, car,
                            row['id'])

            repairs.append(repair)

    return repairs
コード例 #5
0
def select_all():

    # create empty list
    repairs = []

    sql = "SELECT * FROM repairs ORDER BY repair_date DESC"
    results = run_sql(sql)

    for row in results:
        # using mechanic_id from repairs, retrieve mechanic object
        mechanic = mechanic_repository.select(row['mechanic_id'])

        # using car_id from repairs, retrieve car object
        car = car_repository.select(row['car_id'])

        # create Repair object, assign to variable 'repair'
        repair = Repair(row['repair_date'], row['details'], mechanic, car,
                        row['id'])

        repairs.append(repair)

    return repairs
コード例 #6
0
def get_rapair_details(mechanic_id, car_id):
    repairs = []

    # using mechanic_id from repairs, retrieve mechanic object
    mechanic = mechanic_repository.select(mechanic_id)

    # using car_id from repairs, retrieve car object
    car = car_repository.select(car_id)

    sql = "SELECT * FROM repairs WHERE mechanic_id = %s AND car_id = %s"
    values = [mechanic_id, car_id]  # a list is supplied to run_sql

    results = run_sql(sql, values)

    for row in results:
        # create Repair object, assign to variable 'repair'
        repair = Repair(row['repair_date'], row['details'], mechanic, car,
                        row['id'])

        repairs.append(repair)

    return repairs
コード例 #7
0
def show(id):
    mechanic = mechanic_repository.select(id)
    mechanic_cars_repaired = mechanic_repository.cars_repaired(mechanic)

    return render_template("mechanics/show.html", mechanic=mechanic, cars_repaired=mechanic_cars_repaired)