def post(self): if not isUserCook(self): self.redirect("/") return category = db.get(self.request.get('ingredientCategoryKey')) ingredient = Ingredient() ingredient.name = self.request.get('ingredient_name') ingredient.category = category ingredient.put() addIngredient(ingredient) self.redirect('/ingredient?ingredientKey=%s&source=%s' % (ingredient.key(), category.key()))
def post(self): if not isUserCook(self): self.redirect("/") return #Check if ingredient exists ingredientKey=self.request.get('ingredientKey') if ((ingredientKey != None) and (ingredientKey != "")): #Ingredient must exist ingredient = Ingredient.get(ingredientKey) ingredientCategoryKey=self.request.get('ingredientCategoryKey') if ((ingredientCategoryKey != None) and (ingredientCategoryKey != "")): ingredient.category = IngredientCategory.get(ingredientCategoryKey) else: ingredient.category = None price=self.request.get('price') energy=self.request.get('energy') protein=self.request.get('protein') carbs=self.request.get('carbs') fat=self.request.get('fat') fiber=self.request.get('fiber') if ((price != None) and (price != "")): ingredient.price = float(price) if ((energy != None) and (energy != "")): ingredient.energy = float(energy) if ((protein != None) and (protein != "")): ingredient.protein = float(protein) if ((carbs != None) and (carbs != "")): ingredient.carbs = float(carbs) if ((fat != None) and (fat != "")): ingredient.fat = float(fat) if ((fiber != None) and (fiber != "")): ingredient.fiber = float(self.request.get('fiber')) ingredient.put() modifyIngredient(ingredient) sourceKey=self.request.get('source') if ((sourceKey == ingredientCategoryKey) and (sourceKey!=None) and (sourceKey != "")): if ingredient.category != None: self.redirect('/ingredientCategory?ingredientCategoryKey=%s' % ingredient.category.key()) return else: self.redirect('/ingredient') return else: self.redirect('/ingredient') return else: ingredient = Ingredient() ingredient.name = self.request.get('ingredient_name') ingredient.put() addIngredient(ingredient) self.redirect('/ingredient?ingredientKey=%s' % ingredient.key())