def select(id):
    product = None
    sql = "SELECT * FROM products WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        record_label = record_label_repository.select(result['record_label_id'])
        product = Product(result['title'], result['artist'], record_label, result['format'], result['genre'], result['quantity'], result['buy_cost'], result['sell_price'], result['id'])
    return product
def select_all():
    products = []

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

    for row in results:
        record_label = record_label_repository.select(row['record_label_id'])
        product = Product(row['title'], row['artist'], record_label, row['format'], row['genre'], row['quantity'], row['buy_cost'], row['sell_price'], row['id'])
        products.append(product)
    return products
Example #3
0
def update_product(id):
    title = request.form['title']
    artist = request.form['artist']
    record_label = record_label_repository.select(request.form['record_label_id'])
    format = request.form['format']
    genre = request.form['genre']
    quantity = request.form['quantity']
    buy_cost = request.form['buy_cost']
    sell_price = round(float(request.form['sell_price']) * float(request.form['on_sale']),2)
    product = Product(title, artist, record_label, format, genre, quantity, buy_cost, sell_price, id)
    product_repository.update(product)
    return redirect("/products")
Example #4
0
def create_product():
    record_label_id = request.form['record_label_id']
    title = request.form['title']
    artist = request.form['artist']
    record_label = record_label_repository.select(record_label_id)
    format = request.form['format']
    genre = request.form['genre']
    quantity = request.form['quantity']
    buy_cost = request.form['buy_cost']
    sell_price = request.form['sell_price']
    product = Product(title, artist, record_label, format, genre, quantity, buy_cost, sell_price)
    product_repository.save(product)
    return redirect("/products")
Example #5
0
def edit_record_label(id):
    record_label = record_label_repository.select(id)
    return render_template("record_labels/edit.html", title = "Edit Record Label", record_label=record_label)
Example #6
0
def show(id):
    record_label = record_label_repository.select(id)
    products = record_label_repository.products(record_label)
    return render_template("record_labels/show.html", record_label=record_label, products=products)