Exemplo n.º 1
0
    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.queryById(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
Exemplo n.º 2
0
	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))
Exemplo n.º 3
0
    def get(self, questionId):
        question = Question.queryById(questionId)
        answers = Answer.queryByQuestionId(questionId)
        print answers[0].answer_content
        user = self.get_current_user()
        for answer in answers:
            print "answer.answer_content", answer.answer_content
            vote = {"user": "******"}
            print vote["user"]
            answer.vote = vote
            print answer.vote["user"]
            showmax = 5
            answer.showmax = 2

            # 获取投赞同票人name
            votename = Answer_AnswerVote.queryByAnswerId(answer.answer_id, 1)
            answer.votename = votename

            # 判读是否已经投赞同票
            if user.name in votename:
                answer.agreeActive = 1
            else:
                answer.agreeActive = 0

                # 判读是否投反对票
            votename = Answer_AnswerVote.queryByAnswerId(answer.answer_id, -1)
            if user.name in votename:
                answer.againstActive = 1
            else:
                answer.againstActive = 0

            print "answer.answer_id", answer.answer_id
            print "votename", votename
            print "user.name", user.name
            print "answer.agreeActive", answer.agreeActive
            # 今天的日期
            today = datetime.date.today()
            # 今天日期的时间戳
            todayStamp = int(time.mktime(today.timetuple()))

            # 回答时间
            answerStamp = answer.add_time
            t = time.localtime(answerStamp)
            # 判断是否为今天回答
            if answerStamp - todayStamp > 0:
                # 今天的回答只截取日期和时间
                addTimeStr = time.strftime("%H:%M", t)
            else:
                addTimeStr = time.strftime("%Y-%m-%d", t)

            answer.addTimeStr = addTimeStr

        self.render(
            "question/question_detail.html", question=question, questionId=questionId, answers=answers, user=user
        )
Exemplo n.º 4
0
    def post(self):
        # try:
        # print 'begin'
        # answerContent = self.get_argument("answer_content")
        # print 'end'
        # except :
        # print traceback.print_exc()
        # print 'error'
        # print 'hi'

        answerContent = self.get_argument("answer_content")
        questionId = self.get_argument("question_id")
        print "answerContent:", answerContent
        # questionId = 1
        userId = self.get_current_user_id()
        print "userId", userId
        # user = self.get_current_user()
        Answer.addAnswer(questionId, answerContent, userId)

        result = {"errno": 1, "err": ""}
        self.write(result)