Example #1
0
	def get(self):
		user_hash = self.request.get(PARAM_USER_ID)
		userID = wutil.validateUser(user_hash)
		if userID is None:
			return # TODO return an identifiable error
		foodID = int(self.request.get(PARAM_FOOD_ID))
		vote 	  = self.request.get(PARAM_VOTE)

		if vote == '1':
			vote = 1
		else:
			vote = 0

		entry = entities.FoodLocation.get_by_id(foodID)

		food_vote = db.GqlQuery("select * from FoodVote where foodLocationID=%s and userID=%s" % (foodID, userID))
		food_vote = food_vote.get()

		if food_vote == None:
			food_vote = entities.FoodVote(userID = userID, foodLocationID = foodID, vote = vote, voteDate = datetime.now())
			entry.totalVotes += 1
			entry.upvotes += vote

		else:
			if food_vote.vote == -1: # food_vote exists because a comment was added before voting
				entry.totalVotes += 1
				entry.upvotes += vote

				food_vote.vote = vote
				food_vote.voteDate = datetime.now()

			else: # vote was changed
				if food_vote.vote == 0 and vote == 1: # went from downvote to upvote
					entry.upvotes += vote

					food_vote.vote = vote
					food_vote.voteDate = datetime.now()

				if food_vote.vote == 1 and vote == 0: # went from upvote to downvote
					entry.upvotes -= 1

					food_vote.vote = vote
					food_vote.voteDate = datetime.now()

		# commit changes
		entry.put()
		food_vote.put()

		# TODO: some kind of actual response
		self.response.headers['Content-Type'] = "application/json; charset=utf-8"
Example #2
0
	def post(self):
		food_id = self.request.get("food")
		vote = self.request.get("vote")
		
		user_hash = self.request.cookies.get(PARAM_USER_ID, None)
		if user_hash is None:
			return
		userID = wutil.validateUser(user_hash)
		if userID is None:
			return # TODO return an identifiable error

		expires = datetime.now() + timedelta(hours=1)
		dead_date = expires.strftime('%a, %d-%b-%Y %H:%M:%S')

		food_type = dd.castVote(vote, int(food_id), userID)
		self.response.headers.add_header('Set-Cookie', '%s=%s; Path=/; expires=%s;' % (str(food_id), str(vote), dead_date))

		# redirect time
		refer = self.request.headers["Referer"]
		self.redirect(refer)
Example #3
0
	def post(self):
		food_id = self.request.get("food")
		comment = self.request.get("comment")
		food_type = self.request.get("type")

		user_hash = self.request.cookies.get(PARAM_USER_ID, None)
		if user_hash is None:
			return
		userID = wutil.validateUser(user_hash)
		if userID is None:
			return # TODO return an identifiable error

		self.write("user: %s - foodID: %s - comment: %s" % (userID, food_id, comment))

		# strip html tags
		comment = dd.strip_tags(comment)
		# make comment and redirect
		dd.addComment(comment, int(food_id), userID)
		# redirect time
		refer = '/food/?type=%s' % food_type
		self.redirect(refer)
Example #4
0
	def get(self):
		user_hash = self.request.get(PARAM_USER_ID)
		userID = wutil.validateUser(user_hash)
		if userID is None:
			return # TODO return an identifiable error
		
		foodID = int(self.request.get(PARAM_FOOD_ID))
		comment   = self.request.get(PARAM_COMMENT)

		entry = entities.FoodLocation.get_by_id(foodID)

		# if user voted, there will be a food_vote entry already created
		food_vote = db.GqlQuery("select * from FoodVote where foodLocationID=%s and userID=%s" % (foodID, userID))
		food_vote = food_vote.get()

		if food_vote == None: # if no entry exists, create one
			food_vote = entities.FoodVote(userID = userID, foodLocationID = foodID, comment = comment, commentDate = datetime.now())
		else:
			food_vote.comment = comment
			food_vote.commentDate = datetime.now()
		food_vote.put()

		# TODO, respond with some kind of status code to indicate success
		self.response.headers['Content-Type'] = "application/json; charset=utf-8"