Exemple #1
0
def recipes():
    # get a specific recipe
    key = request.args.get('key')
    recipe = Recipe.get(key)
    print recipe

    if not recipe:
        return json.dumps({'error': 'Recipe not found'}), 500

    recipe_object = {
        'name': recipe.name,
        'prepTime': recipe.prepTime,
        'instructions': recipe.instructions
    }
    ingredientList = []
    for i in recipe.ingredients:
        ing = Ingredient.get(i)
        ingredientList.append({
            'ing_name': ing.name,
            'ing_key': str(ing.key())
        })

    recipe_object['ingredients'] = ingredientList

    return json.dumps({'status': 'OK', 'recipe': recipe_object}), 200
Exemple #2
0
 def put(self, key):
     ingredient = Ingredient.get(key)
     form = json.loads(self.request.get('form'))
     ingredient.name = form['name']
     ingredient.price = float(form['price'])
     ingredient.abv = int(form['abv'])
     ingredient.put()
Exemple #3
0
def recipes_add_ingredient():
    # associates an ingredient with a recipe
    recipe_key = request.args.get('recipe')
    ingredient_key = request.args.get('ingredient')

    recipe = Recipe.get(recipe_key)

    if not recipe:
        return json.dumps({'error': 'Recipe not found'}), 500

    ingredient = Ingredient.get(ingredient_key)
    if not ingredient:
        return json.dumps({'error': 'Ingredient not found.'}), 500

    if ingredient.key() in recipe.ingredients:
        return json.dumps({'status': 'Ingredient already in recipe.'}), 200

    # if the ingredient is not already associated, associate it
    recipe.ingredients.append(ingredient.key())
    recipe.put()

    # add the recipe to the ingredient's list of recipes that use it
    if recipe.key() not in ingredient.usedIn:
        ingredient.usedIn.append(recipe.key())
        ingredient.put()

    return json.dumps(
        {'status': 'Associated ingredient and recipe successfully'}), 200
Exemple #4
0
 def put(self, key):
     ingredient = Ingredient.get(key)
     form = json.loads(self.request.get('form'))
     ingredient.name = form['name']
     ingredient.price = float(form['price'])
     ingredient.abv = int(form['abv'])
     ingredient.put()
Exemple #5
0
    def get(self, ingredient_key):
        i = Ingredient.get(ingredient_key)
        if i == None:
            # TODO: error page?
            return

        # Gather all the recipes for all the QIs for this ingredient
        recipes = uniq([qi.recipe for qi in i.quantifiedingredient_set],
                       lambda x: x.title)

        buckets,keys = bucketize(recipes, lambda x: x.title)
        templatevalues = RequestContext(self.request, {
                'ingredient' : i,
                'recipes' : recipes,
                'buckets' : buckets,
                'keys' : keys
                })
        path = os.path.join(os.path.dirname(__file__), 'recipes_by_ingredient.html')
        self.response.out.write(template.render(path, templatevalues))
Exemple #6
0
 def get(self, key):
     ingredient = Ingredient.get(key)
     return self.render('ingredient', {'ingrdient': ingredient})
Exemple #7
0
 def delete(self, key):
     Ingredient.get(key).delete()
Exemple #8
0
 def get(self, key):
     ingredient = Ingredient.get(key)
     return self.render('ingredient', {'ingrdient': ingredient})
Exemple #9
0
 def delete(self, key):
     Ingredient.get(key).delete()