def setUp(self):
     self.whisky_1 = Whisky("Classic Laddie", "Single Malt", "Coastal")
     self.whisky_2 = Whisky("Famous Grouse", "Blended Whisky", "Cereal")
     self.whisky_3 = Whisky("Port Charlotte 10", "Single Malt", "Peated")
     self.distillery_1 = Distillery("Bruichladdich", "Islay", 1881,
                                    [self.whisky_1, self.whisky_3])
     self.distillery_2 = Distillery("Aberlour", "Speyside", 1879)
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
Exemple #3
0
def update_whisky(id):
    name = request.form["name"]
    type = request.form["type"]
    flavour_profile = request.form["flavour_profile"]
    distillery_id = request.form["distillery_id"]
    whisky = Whisky(name, type, flavour_profile, distillery_id, id)
    whisky_repository.update(whisky)
def select_whiskies_of_distillery(id):
    whiskies = []
    sql = "SELECT * FROM whiskies WHERE distillery_id = %s"
    values = [id]
    results = run_sql(sql,values)
    for result in results:
        whisky = Whisky(result["name"], result["type"], result["flavour_profile"], result["id"], result["whiskies"], result["distillery_id"])
        whiskies.append(whisky)
    return whiskies
def get_wishlist_of_user(id):
    whiskies = []
    sql = "SELECT whiskies.* FROM whiskies INNER JOIN wishlists ON wishlists.whisky_id = whiskies.id WHERE wishlists.user_id = %s"
    values = [id]
    results = run_sql(sql, values)
    for result in results:
        distillery_id = result["distillery_id"]
        if distillery_id != None:
            distillery = whisky_repository.get_distillery(distillery_id)
            whisky = Whisky(result["name"], result["type"],
                            result["flavour_profile"], distillery,
                            result["id"])
            whiskies.append(whisky)
        else:
            whisky = Whisky(result["name"], result["type"],
                            result["flavour_profile"], None, result["id"])
            whiskies.append(whisky)
    return whiskies
Exemple #6
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")
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
Exemple #8
0
 def setUp(self):
     self.whisky_1 = Whisky("Classic Laddie", "Single Malt", "Coastal")
     self.whisky_2 = Whisky("Famous Grouse", "Blended Whisky")
     self.whisky_3 = Whisky("Port Charlotte 10", "Single Malt", "Peated")
user_4 = User("Wes Farren")
user_repository.save(user_4)

user_5 = User("Graeme Anderson")
user_repository.save(user_5)

distillery_1 = Distillery("Bruichladdich", "Islay", 1881)
distillery_repository.save(distillery_1)

distillery_2 = Distillery("Aberlour", "Speyside", 1879)
distillery_repository.save(distillery_2)

distillery_3 = Distillery("Dalwhinnie", "Highlands", 1898)
distillery_repository.save(distillery_3)

whisky_1 = Whisky("Classic Laddie", "Single Malt", "Coastal", distillery_1)
whisky_repository.save(whisky_1)

whisky_2 = Whisky("Famous Grouse", "Blended Whisky", "Cereal")
whisky_repository.save(whisky_2)

whisky_3 = Whisky("Monkey Shoulder", "Blended Malt", "Spicy")
whisky_repository.save(whisky_3)

whisky_4 = Whisky("A'Bunadh", "Single Malt", "Rich", distillery_2)
whisky_repository.save(whisky_4)

whisky_5 = Whisky("Victoriana", "Single Malt", "Fruity")
whisky_repository.save(whisky_5)

whisky_6 = Whisky("Port Charlotte 10", "Single Malt", "Smokey", distillery_1)