예제 #1
0
	def post(self):
		if not isUserCook(self):
			self.redirect("/")
			return
		# Retrieve the dish
		dish = db.get(self.request.get('dishKey'))
		if ((self.request.get('dishIngredientKey') != None) and (self.request.get('dishIngredientKey') != "")):
		# If its a modification
			ingredientToDish = db.get(self.request.get('dishIngredientKey'))
			ingredientToDish.quantity = float(self.request.get('quantity'))
			ingredientToDish.put()
			#Modification of basic data
			modifyDish(str(dish.key()), dish.title, dish.subtitle, dish.description, dish.category, dish.eggFree, dish.milkFree, dish.codeModifier)
		else:
			# Retrieve the ingredient
			ingredientKey = self.request.get('ingredientKey')
			ingredient = db.get(ingredientKey)
			quantity = float(self.request.get('quantity'))
			ingredientListItem = IngredientListItem()
			ingredientListItem.quantity = quantity
			ingredientListItem.dish = dish
			ingredientListItem.ingredient = ingredient
			ingredientListItem.put()
			modifyDish(str(dish.key()), dish.title, dish.subtitle, dish.description, dish.category, dish.eggFree, dish.milkFree, dish.codeModifier)
		self.redirect('/dish?dishKey=%s' % str(dish.key()))
예제 #2
0
	def post(self):
		if not isUserCook(self):
			self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
			self.redirect("/")
			return
		dishKey=self.request.get('dishKey')
		if ((dishKey != None) and (dishKey != "")):
		#Modification of basic data
			title = self.request.get('title')
			subtitle = self.request.get('subtitle')
			description = self.request.get('description')
			eggFree = (self.request.get('eggFree') == "yes")
			milkFree = (self.request.get('milkFree') == "yes")
			dishCategoryKey=self.request.get(DISH_CATEGORY_KEY)
			codeModifier=self.request.get(DISH_CODE_MODIFIER)
			dishCategory=None
			if ((dishCategoryKey != None) and (dishCategoryKey != "")):
				dishCategory = db.get(dishCategoryKey)
			modifyDish(dishKey, title, subtitle, description, dishCategory, eggFree, milkFree, codeModifier)
			self.redirect('/dish?dishKey=%s' % self.request.get('dishKey'))
			return
		else:
			dish = Dish()
			dish.creationDate = datetime.datetime.today().date()
			dish.title = self.request.get('title')
			dish.subtitle = self.request.get('subtitle')
			dish.description = self.request.get('description')
			dish.category = DishCategory.get(self.request.get('dishCategoryKey'))
			eggFree = (self.request.get('eggFree') == "yes")
			milkFree = (self.request.get('milkFree') == "yes")
			dish.milkFree = milkFree
			dish.eggFree = eggFree
			dish.put()
			addDish(dish)
			self.redirect('/dish?dishKey=%s' % str(dish.key()))
예제 #3
0
	def post(self):
		if not isUserCook(self):
			self.redirect("/")
			return
		category = db.get(self.request.get(DISH_CATEGORY_KEY))
		dish = db.get(self.request.get(DISH_KEY))
		dish.category = None
		modifyDish(dish);
		dish.put()
		self.redirect(DISH_CATEGORY_URL+'?'+DISH_CATEGORY_KEY+'=%s' % category.key())
예제 #4
0
	def post(self):
		if not isUserCook(self):
			self.redirect("/")
			return
		# Retrieve the dish
		dish = db.get(self.request.get('dishKey'))
		ingredientToDish = db.get(self.request.get('dishIngredientKey'))
		ingredientToDish.delete()
		modifyDish(str(dish.key()), dish.title, dish.subtitle, dish.description, dish.category, dish.eggFree, dish.milkFree, dish.codeModifier)
		self.redirect('/dish?dishKey=%s' % str(dish.key()))
예제 #5
0
def modifyIngredient(ingredientDb):
	client = memcache.Client()
	key = str(ingredientDb.key())
	# Update dishes old category
	ingredientObject = getIngredient(key)
	categoryKey = None
	ret = "Modify "
	ret += str(ingredientObject['category'])
	if ingredientDb.category != None:
		ret += "Had category"
		ret = ret + "<br/>"
		categoryKey = str(ingredientDb.category.key())
	if ingredientObject != None and ingredientObject['category']!=None and ingredientObject['category']['key'] != categoryKey:
		# Update category objects in cacge
		ret = ret + "Must remove"
		ret = ret + "<br/>"
		ret = ret + removeIngredientFromCategory(ingredientObject['category']['key'], key)
	# Create object
	newIngredientObject=createIngredientDb(ingredientDb)
	if ingredientObject == None or (categoryKey != None and (ingredientObject["category"] == None or ingredientObject["category"]['key'] != categoryKey)):
		addIngredientToCategory(categoryKey, newIngredientObject)
	else:
		if categoryKey!= None:
			# Modify ingredientDb in category
			category = client.get(categoryKey)
			if category != None:
				newIngredients = []
				for ingredient in category['ingredients']:
					if ingredient['key'] == key:
						ingredient = newIngredientObject
					newIngredients.append(ingredient)
				category['ingredients'] = newIngredients
				client.set(categoryKey, category)
	# Adds ingredient
	# TODO modify dishes containing this ingredient
	if (differenceToPropagate(ingredientObject, newIngredientObject)):
		for dishIngredient in ingredientDb.dishes:
			dishKey = str(dishIngredient.dish.key())
			title = dishIngredient.dish.title
			subtitle = dishIngredient.dish.subtitle
			description = dishIngredient.dish.description
			dishCategory = dishIngredient.dish.category
			modifyDish(dishKey, title, subtitle, description, dishCategory, dishIngredient.dish.eggFree, dishIngredient.dish.milkFree, dishIngredient.dish.codeModifier)
	client.set(key, newIngredientObject)
	# Adds ingredient to ingredient list
	ingredients = client.get(INGREDIENTS_KEY)
	if ingredients != None:
		newIngredients = []
		for ingredient in ingredients:
			if ingredient['key'] == key:
				ingredient = newIngredientObject
			newIngredients.append(ingredient)
		client.set(INGREDIENTS_KEY, newIngredients)
	return ret