def edit_customer(id):
    customer = customer_repository.select(id)
    animals = animal_repository.select_all()
    return render_template("/customers/edit.html",
                           title="Edit Customer",
                           customer=customer,
                           all_animals=animals)
def create_animal():
    print(request.form)
    name = request.form["name"]
    dob = request.form["dob"]
    animal_type = request.form["animal_type"]
    notes = request.form["notes"]
    customer = customer_repository.select(request.form["customer_id"])
    animal = Animal(name, dob, animal_type, notes, customer)
    animal_repository.save(animal)
    return redirect("/animals")
def select(id):
    animal = None
    sql = "SELECT * FROM animals WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        customer = customer_repository.select(result['customer_id'])
        animal = Animal(result['name'], result['dob'], result['animal_type'],
                        result['notes'], customer, result['id'])
    return animal
def select_all():
    animals = []

    sql = "SELECT * FROM animals ORDER by name"
    results = run_sql(sql)

    for row in results:
        customer = customer_repository.select(row['customer_id'])
        animal = Animal(row['name'], row['dob'], row['animal_type'],
                        row['notes'], customer, row['id'])
        animals.append(animal)
    return animals
def update_animal(id):
    # takes data from form
    name = request.form["name"]
    dob = request.form["dob"]
    animal_type = request.form["animal_type"]
    notes = request.form["notes"]
    customer = customer_repository.select(request.form["customer_id"])

    # make new instance of an Animal using data as constructor values

    animal = Animal(name, dob, animal_type, notes, customer)

    # add this new animal object to animal list
    animal_repository.save(animal)
    return redirect("/animals")
def create_order():
    order_timestamp = request.form['order_timestamp']
    customer_id = request.form['customer']
    restaurant_id = request.form['restaurant']
    dish_ids = request.form.getlist('dishes')

    customer = customer_repository.select(customer_id)
    restaurant = restaurant_repository.select(restaurant_id)

    new_order = Order(order_timestamp, customer, restaurant)
    order_repository.save(new_order)

    order_dishes = []
    for id in dish_ids:
        new_order_dish = OrderDish(new_order, dish_repository.select(id))
        order_dish_repository.save(new_order_dish)
        order_dishes.append(new_order_dish)

    return redirect('/orders')
def update_order(order_id):
    timestamp = request.form["order_timestamp"]
    customer_id = request.form["customer"]
    restaurant_id = request.form["restaurant"]
    dish_ids = request.form.getlist('dishes')

    customer = customer_repository.select(customer_id)
    restaurant = restaurant_repository.select(restaurant_id)

    update_order = Order(timestamp, customer, restaurant, order_id)
    order_repository.update(update_order)

    updated_order_dishes = []
    for id in dish_ids:
        updated_order_dish = OrderDish(update_order,
                                       dish_repository.select(id))
        order_dish_repository.save(updated_order_dish)
        updated_order_dishes.append(updated_order_dishes)

    return redirect("/orders")
Exemple #8
0
def edit_customer(id):
    customer = customer_repository.select(id)
    return render_template('customers/edit.html', customer=customer)
Exemple #9
0
def show_customer(id):
    customer = customer_repository.select(id)
    return render_template("customers/show.html", customer=customer)
def edit_customer(id):
    customer = customer_repository.select(id)
    all_gyms = gym_repository.select_all()
    return render_template("customers/edit.html", customer=customer, all_gyms=all_gyms)