コード例 #1
0
ファイル: questionHandler.py プロジェクト: hellowego/auto
	def post(self, answerId):
		print 'hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii'
		print answerId
		message = self.get_argument("message")
		userId = self.get_current_user_id()
		answer = Answer.queryByAnswerId(answerId)
		# 异常1 回答不存在
		if not answer :
			self.write(Util.response(None, -1, u'回复不存在'))
			return

		# 请输入评论内容
		if message == "":
			self.write(Util.response(None, -1, u'请输入评论内容'))
			return

		# 不能评论锁定的问题
		question = Question.queryById(answer.question_id)
		if question.lock == 1 :
			self.write(Util.response(None, -1, u'不能评论锁定的问题'))
			return

		# 你没有发表评论的权限(略)
		
		# 插入一条评论
		AnswerComment.addAnswerComment(answerId, userId, message)
		rsm = {'item_id':answerId, 'type_name':'answer'}
		self.write(Util.response(rsm, 1, None))
コード例 #2
0
ファイル: questionHandler.py プロジェクト: hellowego/auto
	def post(self):
		answer_id = self.get_argument("answer_id")
		print "answer_id", answer_id
		vote_value = self.get_argument("value")
		
		print "vote_value", vote_value
		answer_info = Answer.queryByAnswerId(answer_id)
		userId = self.get_current_user_id()
		# 获取投票信息
		vote_info = AnswerVote.queryByAnswerIdAndUserId(answer_id, userId)
				
		# 赞同投票结果分三种情况
		# 情况一 没有投过票,增加一条投票记录
		if not vote_info :
			print 'vote_info', vote_info
			AnswerVote.addAnswerVote(answer_id, answer_info.uid, userId, vote_value)
		# 情况二 已经投过赞同票,则删除赞同记录(已经头赞同票,再点一次是为了取消赞同)
		else :
			print 'vote_info.vote_value', vote_info.vote_value
			if vote_info.vote_value == int(vote_value) :
				print 'already vote'				
				AnswerVote.deleteByVoterId(vote_info.voter_id)
		# 情况三 已经投反对票的,将反对票更新为赞同票
			if vote_info.vote_value != int(vote_value) :
				print 'against'
				AnswerVote.updateByVoterId(vote_info.voter_id, vote_value)
		
		# 统计总票数
		agree_count = AnswerVote.countByAnswerIdAndType(answer_id, 1)
		against_count = AnswerVote.countByAnswerIdAndType(answer_id, -1)
		
		# 更新answer投票数
		Answer.updateVoteByAnswerId(answer_id, vote_value, against_count, agree_count)
		print answer_info.uid
		print answer_info.answer_content