def getDaysAvailableMenuItems(day):
	client = memcache.Client()
	key = MENU_ITEMS_FOR_DAY+ str(day)
	daysItems = client.get(key)
	if daysItems == None:
		menuItems = MenuItem.all().filter("day = ", day).filter("containingMenuItem = ", None)
		daysItems=[]
		for menuItem in menuItems:
			menuItemObject = createMenuItemData(menuItem)
			daysItems.append(menuItemObject)
		client.set(key,daysItems)
	# Fetch dishes for menu items
	ret = []
	for menuItem in daysItems:
		sumprice = 0
		dish = getDish(menuItem['dishKey'])
		menuItem['dish'] = dish
		if dish != None:
			sumprice = dish['price']
		components = []
		for subItemKey in menuItem['componentKeys']:
			component = getMenuItem(subItemKey)
			components.append(component)
			componentDish = getDish(component['dishKey'])
			if componentDish != None:
				sumprice = sumprice + componentDish['price']
		menuItem['sumprice'] = sumprice
		menuItem['components'] = components
		ret.append(menuItem)
	return ret
def getCategoryWithDishes(key):
	client = memcache.Client()
	category = client.get(key)
	if category == None:
		categoryDb = DishCategory.get(key)
		if categoryDb != None:
			category = createCategoryObject(categoryDb);
			client.set(key, category)
		else:
			return None
	# Fetch dishes
	dishes = []
	for dishKey in category['dishKeys']:
		dishes.append(getDish(dishKey))
	category['dishes'] = dishes
	return category
Example #3
0
	def get(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 != "")):
		# A single dish with editable ingredient list
			dish=getDish(dishKey)
			#Check if category exists
			ingredients = dish['ingredients']
			dish['energy'] = 0
			for ingredient in ingredients:
				dish['energy'] = dish['energy'] + ingredient['quantity'] * ingredient['energy'] / 100.0
			gotIngredients = getIngredients()
			availableIngredients = sorted(gotIngredients, key=lambda ingredient:ingredient['name'])
			gotCategories = getDishCategories()
			availableCategories = sorted(gotCategories, key=lambda category:category['name'])
			template_values = {
				'dish': dish,
				'availableCategories':availableCategories,
				'availableIngredients':availableIngredients,
				'add_url':"/addIngredientToDish",
				'delete_url':"/deleteIngredientFromDish"
			}
			template = jinja_environment.get_template('templates/dish.html')
			self.printPage(dish['title'], template.render(template_values), False, False)
		else:
		# All the dishes
			unprocessedDishes = Dish.gql("ORDER BY title")
			dishes = []
			for dish in unprocessedDishes:
				try:
					dish.category
				except ReferencePropertyResolveError:
					dish.category = None
				dishes.append(dish)
			availableCategories = DishCategory.gql("WHERE isMenu = False ORDER BY index")
			template_values = {
			  'dishes': dishes,
			  'availableCategories': availableCategories
			}
			template = jinja_environment.get_template('templates/dish_list.html')
			self.printPage("Receptek", template.render(template_values), False, False)
def getMenuItem(key):
	client = memcache.Client()
	menuItem = client.get(key)
	if menuItem == None:
		try:
			menuItemDb = MenuItem.get(key)
			if menuItemDb == None:
				return None
			menuItem = createMenuItemData(menuItemDb)
			client.set(key,menuItem)
		except:
			return None
	# Fetch dish for menu item and fetch subitem
	try:
		dish = getDish(menuItem['dishKey'])
	except KeyError:
		return None
	eggFree = False
	milkFree = False
	if dish == None:
		creationDate = datetime.datetime.strptime("2011-10-01", "%Y-%m-%d").date()
		menuItem['dish'] = dummyDish()
		sumprice = 0
		energy = 0
		fat = 0
		carbs = 0
		fiber = 0
		protein = 0
	else:
		if dish['creationDate'] == None:
			creationDate = datetime.datetime.strptime("2011-10-01", "%Y-%m-%d").date()
		else:
			creationDate = dish['creationDate']
		menuItem['dish'] = dish
		try:
			eggFree = dish['eggFree']
		except:
			pass
		try:
			milkFree = dish['milkFree']
		except:
			pass
		sumprice = dish['price']
		energy = dish['energy']
		fat = dish['fat']
		carbs = dish['carbs']
		fiber = dish['fiber']
		protein = dish['protein']
	# Calculate sum price
	components = []
	for subItemKey in menuItem['componentKeys']:
		component = getMenuItem(subItemKey)
		if component['creationDate'] > creationDate:
			creationDate = component['creationDate']
		components.append(component)
		componentPrice = component['dish']['price']
		componentEnergy = component['dish']['energy']
		componentFat = component['dish']['fat']
		componentCarbs = component['dish']['carbs']
		componentFiber = component['dish']['fiber']
		componentProtein = component['dish']['protein']
		if componentPrice != None:
			sumprice = sumprice + componentPrice
		if componentEnergy != None:
			energy = energy + componentEnergy
		if componentFat != None:
			fat = fat + componentFat
		if componentCarbs != None:
			carbs = carbs + componentCarbs
		if componentFiber != None:
			fiber = fiber + componentFiber
		if componentProtein != None:
			protein = protein + componentProtein
		eggFree = eggFree and component['eggFree']
		milkFree = milkFree and component['milkFree']
	menuItem['sumprice'] = sumprice
	menuItem['energy'] = energy
	menuItem['fat'] = fat
	menuItem['carbs'] = carbs
	menuItem['fiber'] = fiber
	menuItem['protein'] = protein
	menuItem['creationDate'] = creationDate
	menuItem['components'] = components
	menuItem['eggFree']=eggFree
	menuItem['milkFree']=milkFree
	menuItem['novelty']=((datetime.datetime.today().date() - creationDate).days < 7)
	return menuItem