def createRecipeSave(self, request): # pragma: nocover # I suspect this is going to # drastically change when the chrome # extension branch lands, so i'm not # testing it. """ Save recipes """ data = json.load(request.content) data = { k.encode('utf-8'): v for (k,v) in data.items()} recipe = Recipe() recipe.name = data['name'] recipe.author = data['author'] recipe.urlKey = urlify(recipe.user, recipe.name) for i in data['ingredients']: recipe.ingredients.append(i) for i in data['instructions']: recipe.instructions.append(i) recipe.save()
def createRecipeSave(self, request): """ Save recipes """ data = json.load(request.content) data = {k.encode('utf-8'): v for (k, v) in data.items()} recipe = Recipe() recipe.name = data['name'] recipe.recipeYield = str(data.get('recipeYield')) recipe.user = ICurrentUser(request) recipe.urlKey = urlify(recipe.user.email, recipe.name) if Recipe.objects(urlKey=recipe.urlKey).first(): return ERROR(message=ResponseMsg.renameRecipe) recipe.author = data.get('author', USER().anonymous.givenName) for field in ['tags', 'ingredients', 'instructions']: if data.get(field): for i in data[field]: recipe[field].append(i) recipe.save() return OK(message=recipe.urlKey)