示例#1
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))
示例#2
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
        )