Esempio n. 1
0
def create_whisky():
    name = request.form["name"]
    type = request.form["type"]
    flavour_profile = request.form["flavour_profile"]
    distillery_id = request.form["distillery_id"]
    distillery = distillery_repository.select(distillery_id)
    new_whisky = Whisky(name, type, flavour_profile, distillery)
    whisky_repository.save(new_whisky)
    return redirect("/whiskies")
Esempio n. 2
0
def update_distillery(id):
    name = request.form["name"]
    region = request.form["region"]
    founded = request.form["founded"]
    distillery = distillery_repository.select(id)
    updated_distillery = Distillery(name, region, founded, distillery.whiskies,
                                    id)
    distillery_repository.update(updated_distillery)
    return redirect(f"/distilleries/{id}")
def select_all():
    whiskies = []
    sql = "SELECT * FROM whiskies"
    results = run_sql(sql)
    for result in results:
        distillery = None
        if result["distillery_id"] != None:
            distillery = distillery_repository.select(result["distillery_id"])
        whisky = Whisky(result["name"], result["type"],
                        result["flavour_profile"], distillery, result["id"])
        whiskies.append(whisky)
    return whiskies
def select(id):
    sql = "SELECT * FROM whiskies WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    whisky = None
    if result["distillery_id"] != None:
        distillery_id = result["distillery_id"]
        distillery = distillery_repository.select(distillery_id)
        whisky = Whisky(result["name"], result["type"],
                        result["flavour_profile"], distillery, result["id"])
    else:
        whisky = Whisky(result["name"], result["type"],
                        result["flavour_profile"], None, result["id"])
    return whisky
Esempio n. 5
0
def distillery(id):
    distillery = distillery_repository.select(id)
    return render_template("distilleries/individual.html",
                           distillery=distillery)
Esempio n. 6
0
def edit_distilleries(id):
    distillery = distillery_repository.select(id)
    return render_template("distilleries/edit.html", distillery=distillery)