def apply_brand_edits(id): old_brand = brand_repository.select(id) old_id = old_brand.id modified_brand = Brand(request.form['newBrandName'],request.form['newBrandDescription'],request.form['newBrandWarranty'],old_id) brand_repository.update(modified_brand) return redirect("/edit/brand-edit")
def select(id): sql = "SELECT * FROM products WHERE id=%s" values = [id] result = run_sql(sql, values)[0] if result is not None: product_type = product_type_repository.select( result['product_type_id']) brand = brand_repository.select(result['brand_id']) a_product = Product(result['name'], product_type, brand, result['description'], result['distributor_price'], result['sale_price'], result['warranty_length'], result['id']) return a_product
def select_all(): all_products = [] sql = "SELECT * FROM products" results = run_sql(sql) for row in results: product_type = product_type_repository.select(row['product_type_id']) brand = brand_repository.select(row['brand_id']) a_product = Product(row['name'], product_type, brand, row['description'], row['distributor_price'], row['sale_price'], row['warranty_length'], row['id']) all_products.append(a_product) return all_products
def create_a_product(): product_type = product_type_repository.select(request.form["type_choice"]) product_brand = brand_repository.select(request.form["brand_choice"]) new_product = Product( request.form["newProductName"], product_type, product_brand, request.form["newProductDescription"], request.form["newProductDistPrice"], request.form["newProductSalePrice"], request.form["newProductWarrantyLength"], ) product_repository.save(new_product) new_stock_item = Stock(new_product) stock_repository.save(new_stock_item) return redirect("/fullview")
def edit_a_product(id): old_product = product_repository.select(id) the_id = old_product.id updated_type = product_type_repository.select(request.form["type_choice"]) updated_brand = brand_repository.select(request.form["brand_choice"]) updated_product = Product( request.form["newProductName"], updated_type, updated_brand, request.form["newProductDescription"], request.form["newProductDistPrice"], request.form["newProductSalePrice"], request.form["newProductWarrantyLength"], the_id, ) product_repository.update(updated_product) return redirect("/fullview")
def editor_for_existing_brand(id): brand = brand_repository.select(id) return render_template("/editing/editBrand.html", brand=brand)