def post(self): if not isUserCook(self): self.redirect("/") return ingredientCategory = IngredientCategory() ingredientCategory.name = self.request.get('ingredient_category_name') ingredientCategory.put() addIngredientCategory(ingredientCategory) self.redirect('/ingredientCategory')
def getIngredientCategories(): client = memcache.Client() categories=client.get(CATEGORIES_KEY) if categories == None: categories = IngredientCategory.all().order("name") categoryList=[] for category in categories: categoryList.append(createIngredientCategoryDb(category)) client.set(CATEGORIES_KEY, categoryList) return categoryList return categories
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())
def getIngredientCategoryWithIngredients(key): client = memcache.Client() category = client.get(key) if category == None: categoryDb = IngredientCategory.get(key) if categoryDb != None: ingredient = [] for ingredientDb in categoryDb.ingredients: ingredient.append(createIngredientDb(ingredientDb)) category={ 'key':key, 'name':categoryDb.name, 'ingredients':ingredient } client.set(key, category) else: return None return category