Beispiel #1
0
def autocomplete_ingredients(food_item):

	results = []

	# search = request.args.get('term')
	

	search = '%' + str(food_item) + '%'


	# print search
	query = """SELECT Food_Item.item_id FROM Food_Item WHERE Food_Item.name LIKE %s"""
	result = functions.get_result(query, [search])



	if result is None:
		return []

	all_ingr = []


	for i in range(len(result)):
		ingr_list = functions.get_item_ingredients(result[i]["item_id"])
		for ingredient in ingr_list:
			all_ingr.append(ingredient["name"])

	all_ingr_names = list(set(all_ingr))

	return json.dumps(all_ingr_names)
Beispiel #2
0
def get_item(item_id):
	if not session.get(user_id):
		flash(functions.get_flash_message("not_logged_in"))
		return redirect(url_for('login'))

	item = functions.get_food_item(item_id)

	if not item:
		flash(functions.get_flash_message("no_food_item"))
		return redirect(url_for('index'))

	ingredients = functions.get_item_ingredients(item_id)
	badges = functions.get_item_badges(item_id)

	return render_template('fooditem.html', item=item, ingredients=ingredients, badges=badges)