コード例 #1
0
ファイル: cache_dish.py プロジェクト: lajthabalazs/diet-futar
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()
コード例 #2
0
ファイル: cache_dish.py プロジェクト: lajthabalazs/diet-futar
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
コード例 #3
0
ファイル: cache_dish.py プロジェクト: lajthabalazs/diet-futar
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)