예제 #1
0
파일: api.py 프로젝트: naqada/Cartouche
def getAllUnits():

	results = database.performQuery('SELECT id, name, short_name FROM units ORDER BY name')

	units = []

	for result in results:
		units.append({'id': result['id'], 'name': result['name'], 'short_name': result['short_name']})

	return jsonify({'units': units})
예제 #2
0
파일: api.py 프로젝트: naqada/Cartouche
def getAllIngredients():
	
	results = database.performQuery('SELECT name FROM ingredients ORDER BY name')
	
	ingredients = []
	
	for result in results:
		ingredients.append(result['name'])
	
	return jsonify({'ingredients': ingredients})	
예제 #3
0
파일: api.py 프로젝트: naqada/Cartouche
def getRecipe(recipe_id):
	recipe_id = int(recipe_id)

	results = database.performQuery(
	"""SELECT
		recipes.id,
		recipes.name,
		recipes.directions,
		ingredients.id AS ingredient_id,
		ingredients.name AS ingredient_name,
		l_recipes_to_ingredients.quantity,
		units.name AS units,
		units.short_name AS units_short_name,
		users.id AS user_id
	FROM recipes
	JOIN l_recipes_to_ingredients ON l_recipes_to_ingredients.recipe_id = recipes.id
	JOIN ingredients ON ingredients.id = l_recipes_to_ingredients.ingredient_id
	JOIN units ON units.id = l_recipes_to_ingredients.units
	JOIN users ON users.id = recipes.user_owner
	WHERE recipes.id = %d""" % recipe_id)
	
	recipe = {}
	prev_recipe_id = None
	ingredients = []
	
	recipe_id = int(results[0]['id'])
	recipe_name = results[0]['name']
	recipe_directions = results[0]['directions']
	user_id = results[0]['user_id']
	
	recipe['id'] = recipe_id
	recipe['name'] = recipe_name
	recipe['directions'] = recipe_directions
	recipe['user_id'] = user_id
	
	for result in results:
		ingredient_id = result['ingredient_id']
		ingredient_name = result['ingredient_name']
		quantity = int(result['quantity'])
		units = '%s (%s)' % (result['units'], result['units_short_name'])
		ingredients.append({'id': ingredient_id, 'name': ingredient_name, 'quantity': quantity, 'units': units})
		
	recipe['ingredients'] = ingredients

	return jsonify(recipe)
예제 #4
0
파일: api.py 프로젝트: naqada/Cartouche
def getRecipesForUser(user_id):
	user_id = int(user_id)
	
	results = database.performQuery('SELECT id, name FROM recipes WHERE user_owner = %d' % user_id)
	
	return jsonify({'recipes': results})