def modifyDish(key, title, subtitle, description, dishCategoryDb, eggFree, milkFree, codeModifier): dishDb = Dish.get(key) client = memcache.Client() dishDb.title = title dishDb.subtitle = subtitle dishDb.description = description dishDb.category = dishCategoryDb dishDb.eggFree = eggFree dishDb.milkFree = milkFree dishDb.codeModifier = codeModifier # Update dishes old category dishObject = getDish(key) categoryKey = None if dishDb.category != None: categoryKey = str(dishDb.category.key()) if dishObject != None and dishObject["category"]!= None and dishObject["category"]['key'] != categoryKey: # Update category objects in cacge removeDishFromCategory(dishObject["category"]['key'], key) # Create object newDishObject = createDishObjectDb(dishDb) dishDb.price = int(newDishObject['price']) if ( dishObject == None or dishObject["category"] != categoryKey ) and categoryKey != None: addDishToCategory(categoryKey, key) client.set(key, newDishObject) dishDb.put()
def getDish(key): if key == None: return None client = memcache.Client() dish = client.get(key) if dish == None: dishDb = Dish.get(key) if dishDb != None: dish = createDishObjectDb(dishDb) client.set(dish['key'], dish) return dish
def addDish(dishDb): client = memcache.Client() key = str(dishDb.key()) if dishDb.category != None: categoryKey = str(dishDb.category.key()) addDishToCategory(categoryKey, key) dishKeys = client.get(ALL_DISHES) if dishKeys != None: dishKeys.append(str(dishDb.key())) client.set(ALL_DISHES, dishKeys) dishObject = createDishObjectDb(dishDb) client.set(str(dishDb.key()), dishObject)