Ejemplo n.º 1
0
	def post(self):
		if(not isUserLoggedIn(self)):
			self.redirect("/registration")
			return
		user = None
		userKey=self.session.get(USER_KEY,None)
		if (userKey != None):
			user = db.get(userKey)
		else:
			self.redirect("/profile")
			return
		addressKey = self.request.get("addressKey")
		address = None
		if addressKey != None and addressKey != "":
			address = Address.get(addressKey)
			if address != None:
				if (address.user.email != user.email):
					self.redirect("/profile")
					return
		if address == None:
			address = Address()
		address.user = user
		address.billingName = self.request.get("billingName")
		address.zipNumCode = int(self.request.get("zipNumCode"))
		address.street = self.request.get("street")
		address.streetNumber = self.request.get("streetNumber")
		address.put()
		self.redirect("/profile")
Ejemplo n.º 2
0
	def get(self):
		if not isUserLoggedIn(self):
			self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
			self.redirect("/")
			return
		orderKey = self.request.get('orderKey')
		if orderKey != None:
			order = WebshopOrderItem.get(orderKey)
			order.addressString = order.address.zipNumCode + " " + order.address.street + " " + order.address.streetNumber
			order.price = order.item.price * order.orderQuantity
			if order != None:
				formattedComments = []
				for i in range(0,len(order.comments)):
					formattedComments.append(
						{
							"comment":order.comments[i],
							"author":order.commentAuthors[i],
							"date":order.commentDates[i]
						}
					)
				order.formattedComments = formattedComments
				template_values = {
					'order':order
				}
				template = jinja_environment.get_template('templates/webshop/userOrderDetails.html')
				self.printPage("Rendelés részletei", template.render(template_values), True, True)
				return
		self.printPage("Rendelés részletei", "Missing parameter for user order", True, True)
Ejemplo n.º 3
0
	def post(self):
		if(not isUserLoggedIn(self)):
			self.redirect("/registration")
			return
		clearLoginError(self)
		userKey=self.session.get(USER_KEY,None)
		user = None
		if (userKey != None):
			user = db.get(userKey)
		if user == None:
			self.redirect("/registration")
			return
		else:
			m = hashlib.md5()
			encodedString = self.request.get("oldPassword").encode('ascii', errors='replace')
			m.update(encodedString)
			passwordHash = str(m.hexdigest())

			if user.passwordHash == passwordHash:
				passwd1 = self.request.get("newPassword")
				passwd2 = self.request.get("passwordCheck")
				if passwd1 == passwd2:
					m2 = hashlib.md5()
					encodedString = passwd1.encode('ascii', errors='replace')
					m2.update(encodedString)
					user.passwordHash = str(m2.hexdigest()) 
					user.put()
				else:
					self.session[LOGIN_ERROR_KEY] = REGISTRATION_ERROR_PASSWORD_DOESNT_MATCH
			else:
				self.session[LOGIN_ERROR_KEY] = "Hibas jelszó"
		self.redirect("/profile")
Ejemplo n.º 4
0
	def get(self):
		if not isUserLoggedIn(self):
			self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
			self.redirect("/")
			return
		itemKey = self.request.get('itemKey')
		item = WebshopItem.get(itemKey)
		template_values = {
			'item':item
		}
		template = jinja_environment.get_template('templates/webshop/webshopItemDetails.html')
		self.printPage("Rendelés részletei", template.render(template_values), True, True)
Ejemplo n.º 5
0
	def get(self):
		if(not isUserLoggedIn(self)):
			self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
			self.redirect("/registration")
			return
		user = None
		userKey=self.session.get(USER_KEY,None)
		if (userKey != None):
			user = db.get(userKey)
		referred = sorted(user.referred, key=lambda user:user.registrationDate)
		template_values = {
			'referred' : referred
		}
		template = jinja_environment.get_template('templates/referred.html')
		self.printPage("Profil", template.render(template_values), False, True)
Ejemplo n.º 6
0
	def get(self):
		if(not isUserLoggedIn(self)):
			self.redirect("/registration")
			return
		userKey=self.session.get(USER_KEY,None)
		if (userKey != None):
			user = db.get(userKey)
			user.password = "******"
			user.role = None
			template_values = {
				'user': user,
				LOGIN_ERROR_KEY:self.session.get(LOGIN_ERROR_KEY,0)
			}
			template = jinja_environment.get_template('templates/userForms/profile.html')
			self.printPage("Profil", template.render(template_values), False, True)
Ejemplo n.º 7
0
	def post(self):
		if not isUserLoggedIn(self):
			self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
			self.redirect("/")
			return
		orderKey = self.request.get('orderKey')
		order = WebshopOrderItem.get(orderKey)
		comments = order.comments
		comments.append(self.request.get('message'))
		order.comments = comments
		authors = order.commentAuthors
		authors.append('Én')
		order.commentAuthors = authors
		dates = order.commentDates
		dates.append(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
		order.commentDates = dates
		order.put()
		self.redirect("/webshopUserOrder?orderKey=" + orderKey)
Ejemplo n.º 8
0
	def get(self):
		if not isUserLoggedIn(self):
			self.session[LOGIN_NEXT_PAGE_KEY] = self.URL
			self.redirect("/")
			return
		user = getUser(self)
		if (user!=None):
			orders = user.webshopOrders
			orderedOrders = sorted(orders, key=lambda order: order.orderDate, reverse=True)
			orders = []
			for order in orderedOrders:
				order.addressString = order.address.zipNumCode + " " + order.address.street + " " + order.address.streetNumber
				order.price = order.item.price * order.orderQuantity
				orders.append(order)
			template_values = {
				'orders':orders
			}
			template = jinja_environment.get_template('templates/webshop/userOrderList.html')
			self.printPage("Rendelések", template.render(template_values), True, True)
		else:
			print "Error, no logged in user"
Ejemplo n.º 9
0
	def post(self):
		if(not isUserLoggedIn(self)):
			self.redirect("/registration")
			return
		user = None
		userKey=self.session.get(USER_KEY,None)
		if (userKey != None):
			user = db.get(userKey)
		else:
			self.redirect("/profile")
			return
		addressKey = self.request.get("addressKey")
		address = None
		if addressKey != None and addressKey != "":
			address = Address.get(addressKey)
			if address != None:
				if (address.user.email != user.email):
					self.redirect("/profile")
					return
				address.active = False
				address.put()
		self.redirect("/profile")
Ejemplo n.º 10
0
	def post(self):
		if(not isUserLoggedIn(self)):
			self.redirect("/registration")
			return
		userKey=self.session.get(USER_KEY,None)
		if (userKey != None):
			user = db.get(userKey)
			if user != None:
				user.familyName = self.request.get('familyName')
				user.givenName = self.request.get('givenName')
				user.phoneNumber = self.request.get('phoneNumber')
				user.put()
				user.password = "******"
				user.role = None
				template_values = {
					'user': user,
				}
				template = jinja_environment.get_template('templates/userForms/profile.html')
				self.printPage("Profil", template.render(template_values), False, True)
			else:
				self.redirect("/registration")
		else:
			self.redirect("/registration")
Ejemplo n.º 11
0
	def post(self):
		if(not isUserLoggedIn(self)):
			self.redirect("/registration")
			return
		userKey = self.session.get(USER_KEY,None)
		user=None
		if (userKey != None):
			user = User.get(userKey)
		addresses = user.addresses.filter("active = ", True)
		if addresses.count()==0:
			template = jinja_environment.get_template('templates/no_address.html')
			self.printPage('Rendelesek', template.render(), True)
			return
		actualOrder = self.session.get(ACTUAL_ORDER,{})
		firstOrderableDay = getFirstOrderableDate(self)
		orderTotal = 0
		orderedItems = []
		if (len(actualOrder) > 0):
			# Organize actual order into weeks
			ordersInWeeks = {} # A map holding ordered items with ordered quantiy
			for orderKey in actualOrder.keys():
				orderItemCount = int(actualOrder[orderKey])
				if (orderItemCount != 0):
					item = db.get(orderKey)
					day = item.day
					if day < firstOrderableDay:
						continue
					monday = getMonday(day)
					if ordersInWeeks.has_key(monday):
						weekHolder = ordersInWeeks.get(monday)
					else:
						weekHolder = []
					orderItem = {
						'key' : orderKey,
						'quantity' : orderItemCount
					}
					weekHolder.append(orderItem)
					ordersInWeeks[monday] = weekHolder
			# Go through order week by week
			if len(ordersInWeeks) > 0:
				orderedItemsForMail = {}
				for monday in ordersInWeeks.keys():
					weekHolder = ordersInWeeks.get(monday)
					alreadyOrdered = getUserOrdersForWeek(user, monday)
					# Merge orders for the week
					for item in weekHolder:
						orderedQuantity = item['quantity']
						orderItemKey = item['key']
						# Order should not remove more items than already ordered
						if alreadyOrdered.has_key(orderItemKey):
							alreadyOrderedQuantity = alreadyOrdered.get(orderItemKey)
							if alreadyOrderedQuantity + orderedQuantity < 0:
								orderedQuantity = 0 - alreadyOrderedQuantity
						if isMenuItem(orderItemKey):
							menuItem = getMenuItem(orderItemKey)
							day = menuItem['day']
							menuItem['quantity'] = orderedQuantity
							menuItem['totalPrice'] = orderedQuantity * menuItem['price']
							menuItem['isMenuItem'] = True
							orderTotal = orderTotal + orderedQuantity * menuItem['price']
							orderedItems.append(str(day) + " " + str(orderItemKey) + " " + str(orderedQuantity) + " " + str(menuItem['price']))
							if orderedItemsForMail.has_key(day):
								daysItems = orderedItemsForMail.get(day)
								daysItems.append(menuItem)
							else:
								daysItems = []
								daysItems.append(menuItem)
							orderedItemsForMail[day] = daysItems
						else:
							composit = getComposit(orderItemKey)
							day = composit['day']
							composit['quantity'] = orderedQuantity
							composit['totalPrice'] = orderedQuantity * composit['price']
							composit['isMenuItem'] = False
							orderTotal = orderTotal + orderedQuantity * composit['price']
							orderedItems.append(str(day) + " " + str(orderItemKey) + " " + str(orderedQuantity) + " " + str(composit['price']))
							if orderedItemsForMail.has_key(day):
								daysItems = orderedItemsForMail.get(day)
								daysItems.append(composit)
							else:
								daysItems = []
								daysItems.append(composit)
							orderedItemsForMail[day] = daysItems
						if alreadyOrdered.has_key(orderItemKey):
							orderedQuantity = orderedQuantity + alreadyOrdered.get(orderItemKey)
						if (orderedQuantity > 0):
							alreadyOrdered[orderItemKey] = orderedQuantity
						else:
							alreadyOrdered.pop(orderItemKey, 0)
					# Add stuff to the first week the user created
					daysForMail = orderedItemsForMail.keys()
					sortedDays = sorted(daysForMail)
					sortedItemsForMail = []
					for day in sortedDays:
						sortedItemsForMail.append(
							{'day':day,
							'orders':orderedItemsForMail.get(day)}
						)
					weeks = user.weeks.filter("monday = ", monday)
					if (weeks.count() > 0):
						week = weeks.get()
					else:
						week = UserWeekOrder()
						week = UserWeekOrder()
						week.user = user
						week.monday = monday
						# Add address for every day
						defaultAddress = user.addresses.filter("active = ", True).get()
						week.mondayAddress = defaultAddress
						week.tuesdayAddress = defaultAddress
						week.wednesdayAddress = defaultAddress
						week.thursdayAddress = defaultAddress
						week.fridayAddress = defaultAddress
						week.saturdayAddress = defaultAddress
						week.sundayAddress = defaultAddress
					
					orderedMenuItems = []
					orderedComposits = []
					for itemKey in alreadyOrdered.keys():
							newItem = str(alreadyOrdered.get(itemKey)) + " " + itemKey
							if isMenuItem(itemKey):
								orderedMenuItems.append(newItem)
							else:
								orderedComposits.append(newItem)
					week.orderedMenuItems = orderedMenuItems
					week.orderedComposits = orderedComposits
					week.put()
					user.lastOrder = datetime.datetime.now(timeZone).date()
					user.lastOrderFlag = True
					user.put()
				updateUser(user)
				template_values = {
					"user":user,
					'userOrder':sortedItemsForMail,
				}
				logInfo(self, self.URL, "ORDER_POSTED")
				event = UserOrderEvent()
				event.orderDate = datetime.datetime.now(timeZone)
				event.user = user
				event.price = orderTotal
				event.orderedItems = orderedItems
				event.put()
				# Send email notification to the user
				messageTxtTemplate = jinja_environment.get_template('templates/orderNotificationMail.txt')
				messageHtmlTemplate = jinja_environment.get_template('templates/orderNotificationMail.html')
				message = mail.EmailMessage(sender="Diet Futar <*****@*****.**>")
				message.subject="Diet-futar, rendeles visszaigazolasa"
				message.to = user.email
				message.bcc = "*****@*****.**"
				message.body = messageTxtTemplate.render(template_values)
				message.html = messageHtmlTemplate.render(template_values)
				message.send()


				self.session[ACTUAL_ORDER]={}
				#self.response.out.write(messageTemplate.render(template_values));
				self.redirect("/personalMenu")
			else:
				print "Error #100: Can't process orders."
		else:
				print "Error #100: Can't process orders."
Ejemplo n.º 12
0
	def post(self):
		# Get addresses and comments and save them to the proper day
		# Works only for a singe week view
		if(not isUserLoggedIn(self)):
			self.redirect("/")
			return
		firstOrderableDay=getFirstOrderableDate(self);
		week = None
		for field in self.request.arguments():
			if ((field[:8]=="address_") or (field[:8]=="comment_")):
				day=datetime.datetime.strptime(field[8:], "%Y-%m-%d").date()
				if day < firstOrderableDay:
					continue
				if week == None:
					user = getUser(self)
					monday = getMonday(day)
					weeks = user.weeks.filter("monday = ", monday)
					if weeks.count() == 1:
						week = weeks.get()
				# If no week was determined, continue, nothing to save here
				if week == None:
					continue
				if field[:8]=="address_":
					address=Address.get(self.request.get(field))
					if day.weekday() == 0:
						week.mondayAddress = address
					elif day.weekday() == 1:
						week.tuesdayAddress = address
					elif day.weekday() == 2:
						week.wednesdayAddress = address
					elif day.weekday() == 3:
						week.thursdayAddress = address
					elif day.weekday() == 4:
						week.fridayAddress = address
					elif day.weekday() == 5:
						week.saturdayAddress = address
					elif day.weekday() == 6:
						week.sundayAddress = address
	
				if (field[:8]=="comment_"):
					comment = self.request.get(field)
					if day.weekday() == 0:
						week.mondayComment = comment
					elif day.weekday() == 1:
						week.tuesdayComment = comment
					elif day.weekday() == 2:
						week.wednesdayComment = comment
					elif day.weekday() == 3:
						week.thursdayComment = comment
					elif day.weekday() == 4:
						week.fridayComment = comment
					elif day.weekday() == 5:
						week.saturdayComment = comment
					elif day.weekday() == 6:
						week.sundayComment = comment

		if week != None:
			week.put()

		logInfo(self, self.URL, "MODIFY_ADDRESS_ON_PERSONAL_MENU")
		self.redirect("/personalMenu")
Ejemplo n.º 13
0
	def get(self):
		if(not isUserLoggedIn(self)):
			self.redirect("/")
			return
		day = getOrderBaseDate(self)
		monday = getMonday(day)
		firstOrderableDay = getFirstOrderableDate(self);
		user = getUser(self)
		weeks = user.weeks.filter("monday = ", monday)
		days=[]
		for i in range(0,5):
			actualDayObject={}
			orderedPrice = 0
			actualDay=monday+datetime.timedelta(days=i)
			if actualDay < firstOrderableDay:
				actualDayObject["changable"] = False
			else:
				actualDayObject["changable"] = True
			daysOrderItems = getOrderedItemsFromWeekData(weeks, actualDay)
			actualDayObject['orderedItems'] = daysOrderItems
			for orderedItem in daysOrderItems:
				try:
					orderedPrice = orderedPrice + orderedItem['price'] * orderedItem['orderedQuantity']
				except:
					pass
			actualDayObject['day']=dayNames[i]
			actualDayObject['date'] = actualDay
			actualDayObject["orderedPrice"] = orderedPrice
			if daysOrderItems != None and len(daysOrderItems)>0:
				if (weeks.count() > 0):
					week = weeks.get()
				else:
					week = UserWeekOrder()
				address = getOrderAddress(week, actualDay)
				comment = getOrderComment(week, actualDay)
				if address == None:
					address = user.addresses.get()
				actualDayObject['address'] = address
				actualDayObject['comment'] = comment
				actualDayObject["deliveryCost"] = getZipBasedDeliveryCost(address.zipNumCode, orderedPrice)
			days.append(actualDayObject)
		# A single dish with editable ingredient list
		prevMonday=monday + datetime.timedelta(days=-7)
		nextMonday=monday + datetime.timedelta(days=7)
		today=datetime.date.today()
		actualMonday = getMonday(today)
		availableAddresses = []
		for address in user.addresses:
			address.deliveryCost = getZipBasedDeliveryCost(address.zipNumCode, 0)
			address.deliveryLimit = getZipBasedDeliveryLimit(address.zipNumCode)
			availableAddresses.append(address)
		template_values = {
			'days':days,
			'addresses':availableAddresses,
		}
		if nextMonday <= actualMonday + datetime.timedelta(days=FURTHEST_DAY_DISPLAYED):
			template_values['next'] = nextMonday
		if prevMonday >= actualMonday:
			template_values['prev'] = prevMonday
		# A single dish with editable ingredient list
		template = jinja_environment.get_template('templates/reviewOrderedMenu.html')
		logInfo(self, self.URL, "REVIEW_PERSONAL_MENU")
		self.printPage(str(day), template.render(template_values), False, True)
Ejemplo n.º 14
0
	def printPage(self, title, content, forAnonymus=False, forLoggedIn=False):
		if (title != None and title != ""):
			title = "Diet futar - " + title
		else:
			title="Diet futar"
		template_params={
			"pageTitle":title
		}
		ret=jinja_environment.get_template('templates/headers/header_part_zero.html').render(template_params)
		topMenu=[]
		user = getUser(self)
		if (user != None):
			user.lastPageAccess = datetime.datetime.now(timeZone)
			user.put()
		if isUserAdmin(self):
			dailyMenu={}
			dailyMenu["label"]="Napi menu"
			dailyMenu["target"]="/menuEdit"
			topMenu.append(dailyMenu)
			weeklyMenu={}
			weeklyMenu["label"]="Heti menu"
			weeklyMenu["target"]="/menuWeekEdit"
			topMenu.append(weeklyMenu)
			payingOrders={}
			payingOrders["label"]="Rendelt"
			payingOrders["target"]="/chefReviewOrders"
			topMenu.append(payingOrders)
			toDeliver={}
			toDeliver["label"]="Sz&aacute;llitand&oacute;"
			toDeliver["target"]="/deliveryReviewOrders"
			topMenu.append(toDeliver)
			webShop={}
			webShop["label"]="Term&eacute;kek"
			webShop["target"]="/itemList"
			topMenu.append(webShop)
			webShopOrder={}
			webShopOrder["label"]="WebShop"
			webShopOrder["target"]="/usersOrders"
			topMenu.append(webShopOrder)
			ingredients={}
			ingredients["label"]="Alapanyagok"
			ingredients["target"]="/ingredient"
			topMenu.append(ingredients)
			categories={}
			categories["label"]="Ketegori&aacute;k"
			categories["target"]="/ingredientCategory"
			topMenu.append(categories)
			recepies={}
			recepies["label"]="Receptek"
			recepies["target"]="/dish"
			topMenu.append(recepies)
			dishCategories={}
			dishCategories["label"]="Fog&aacute;sok"
			dishCategories["target"]=DISH_CATEGORY_URL
			topMenu.append(dishCategories)
			userList={}
			userList["label"]="Felhaszn&aacute;l&oacute;k"
			userList["target"]="/userList"
			topMenu.append(userList)
			agent={}
			agent["label"]="Aj&aacute;nlott"
			agent["target"]="/referred"
			topMenu.append(agent)
			siteAdmin={}
			siteAdmin["label"]="Adminisztraci&oacute;"
			siteAdmin["target"]="/siteAdmin"
			topMenu.append(siteAdmin)
			viewLogs={}
			viewLogs["label"]="Logok"
			viewLogs["target"]="/viewLogs"
			topMenu.append(viewLogs)
			crm={}
			crm["label"]="CRM"
			crm["target"]="/crmMainPage"
			topMenu.append(crm)
			onsiteIncome={}
			onsiteIncome["label"]="Facebook l&aacute;togat&oacute;k"
			onsiteIncome["target"]="/weeklyFacebookVisits"
			topMenu.append(onsiteIncome)
			dataDownload={}
			dataDownload["label"]="Adatok let&ouml;lt&eacute;se"
			dataDownload["target"]="/dataDownloadPage"
			topMenu.append(dataDownload)
			newsLetter={}
			newsLetter["label"]="H&iacute;rlev&eacute;l"
			newsLetter["target"]="/newsletter"
			topMenu.append(newsLetter)
		elif isUserCook(self):
			dailyMenu={}
			dailyMenu["label"]="Menu osszeallitas"
			dailyMenu["target"]="/menuEdit"
			topMenu.append(dailyMenu)
			weeklyMenu={}
			weeklyMenu["label"]="Menu attekintes"
			weeklyMenu["target"]="/menuWeekEdit"
			topMenu.append(weeklyMenu)
			payingOrders={}
			payingOrders["label"]="Rendelt"
			payingOrders["target"]="/chefReviewOrders"
			topMenu.append(payingOrders)
			ingredients={}
			ingredients["label"]="Alapanyagok"
			ingredients["target"]="/ingredient"
			topMenu.append(ingredients)
			categories={}
			categories["label"]="Ketegoriak"
			categories["target"]="/ingredientCategory"
			topMenu.append(categories)
			recepies={}
			recepies["label"]="Receptek"
			recepies["target"]="/dish"
			topMenu.append(recepies)
			dishCategories={}
			dishCategories["label"]="Fogasok"
			dishCategories["target"]=DISH_CATEGORY_URL
			topMenu.append(dishCategories)
		elif isUserDelivery(self):
			toDeliver={}
			toDeliver["label"]="Szallitando"
			toDeliver["target"]="/deliveryReviewOrders"
			topMenu.append(toDeliver)
		elif isUserAgent(self):
			agent={}
			agent["label"]="Ajanlott"
			agent["target"]="/referred"
			topMenu.append(agent)
		if len(topMenu) > 0:
			template_params={
				"menuItems":topMenu
			}
			ret=ret + jinja_environment.get_template('templates/admin/adminMenu.html').render(template_params)
		ret=ret + jinja_environment.get_template('templates/headers/header_part_one.html').render()
		#Set menu items
		menuItems=[]
		weeklyOrderMenu={}
		weeklyOrderMenu["label"]="Heti aj&#225;nlat"
		weeklyOrderMenu["target"]="/order"
		menuItems.append(weeklyOrderMenu)
		aboutUsMenu={}
		aboutUsMenu["label"]="R&oacute;lunk"
		aboutUsMenu["target"]="/about"
		menuItems.append(aboutUsMenu)
		servicesMenu={}
		servicesMenu["label"]="Szolg&aacute;ltat&aacute;sok"
		servicesMenu["target"]="/services"
		menuItems.append(servicesMenu)
		glutenMenu={}
		glutenMenu["label"]="Glut&eacute;n&eacute;rz&eacute;kenys&eacute;g"
		glutenMenu["target"]="/gluten"
		menuItems.append(glutenMenu)
		aboutDelivery={}
		aboutDelivery["label"]="Rendel&eacute;si felt&eacute;telek"
		aboutDelivery["target"]="/aboutDelivery"
		menuItems.append(aboutDelivery)
		faqMenu={}
		faqMenu["label"]="GY.I.K."
		faqMenu["target"]="/faq"
		#menuItems.append(faqMenu)
		template_params={
			"menuItems":menuItems
		}
		ret=ret+jinja_environment.get_template('templates/menu.html').render(template_params)
		ret=ret+getUserBox(self)
		ret=ret+jinja_environment.get_template('templates/headers/header_part_two.html').render()
		if forAnonymus or isUserLoggedIn(self):
			ret=ret+content
		else:
			ret=ret + "A tartalom nem jelenitheto meg"
		ret=ret+"</div>"
		ret=ret+jinja_environment.get_template('templates/headers/footer.html').render()
		self.response.out.write(ret)
Ejemplo n.º 15
0
 def post(self):
     if not isUserLoggedIn(self):
         self.redirect("/")
         return
     user = getUser(self)
     aMenuQuantity = int(self.request.get("aMenu"))
     bMenuQuantity = int(self.request.get("bMenu"))
     makosQuantity = int(self.request.get("makos"))
     diosQuantity = int(self.request.get("dios"))
     addressKey = self.request.get("address")
     address = Address.get(addressKey)
     message = self.request.get("message")
     if aMenuQuantity > 0:
         aMenuItems = WebshopItem.all().filter("code = ", CHRISTMAS_LUNCH_A)
         aMenuItem = None
         if aMenuItems.count() == 1:
             aMenuItem = aMenuItems.get()
         christmasOrder = WebshopOrderItem()
         christmasOrder.address = address
         christmasOrder.orderDate = datetime.datetime.now()
         christmasOrder.orderQuantity = aMenuQuantity
         christmasOrder.item = aMenuItem
         christmasOrder.user = user
         if message != None and message != "":
             christmasOrder.comments = [message]
             christmasOrder.commentAuthors = ["&Eacute;n"]
             christmasOrder.commentDates = [datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")]
         christmasOrder.put()
     if bMenuQuantity > 0:
         bMenuItems = WebshopItem.all().filter("code = ", CHRISTMAS_LUNCH_B)
         bMenuItem = None
         if bMenuItems.count() == 1:
             bMenuItem = bMenuItems.get()
         christmasOrder = WebshopOrderItem()
         christmasOrder.address = address
         christmasOrder.orderDate = datetime.datetime.now()
         christmasOrder.orderQuantity = bMenuQuantity
         christmasOrder.item = bMenuItem
         christmasOrder.user = user
         if message != None and message != "":
             christmasOrder.comments = [message]
             christmasOrder.commentAuthors = ["&Eacute;n"]
             christmasOrder.commentDates = [datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")]
         christmasOrder.put()
     if makosQuantity > 0:
         makosItems = WebshopItem.all().filter("code = ", MAKOS_BEIGLI)
         makosItem = None
         if makosItems.count() == 1:
             makosItem = makosItems.get()
         christmasOrder = WebshopOrderItem()
         christmasOrder.address = address
         christmasOrder.orderDate = datetime.datetime.now()
         christmasOrder.orderQuantity = makosQuantity
         christmasOrder.item = makosItem
         christmasOrder.user = user
         if message != None and message != "":
             christmasOrder.comments = [message]
             christmasOrder.commentAuthors = ["&Eacute;n"]
             christmasOrder.commentDates = [datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")]
         christmasOrder.put()
     if diosQuantity > 0:
         diosItems = WebshopItem.all().filter("code = ", DIOS_BEIGLI)
         diosItem = None
         if diosItems.count() == 1:
             diosItem = diosItems.get()
         christmasOrder = WebshopOrderItem()
         christmasOrder.address = address
         christmasOrder.orderDate = datetime.datetime.now()
         christmasOrder.orderQuantity = diosQuantity
         christmasOrder.item = diosItem
         christmasOrder.user = user
         if message != None and message != "":
             christmasOrder.comments = [message]
             christmasOrder.commentAuthors = ["&Eacute;n"]
             christmasOrder.commentDates = [datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")]
         christmasOrder.put()
     self.redirect("/userOrderList")