Пример #1
0
 def accept_answer(cls, ans_id, qn_id):
     print("ans_id:", ans_id, " qn_id:", qn_id)
     handle = AnswerHandler()
     question = handle.accept_answer(ans_id, qn_id)
     if question:
         return True
     return False
Пример #2
0
 def get_answer_by_ans_id(cls, answerId):
     handle = AnswerHandler()
     answer = handle.get_answer_by_ans_id(answerId)
     print(answer)
     if answer:
         return Answer(answer["answer"], answer["qn_id"], answer["user_id"],
                       answer["ans_id"], answer["preferred"])
     return None
Пример #3
0
 def update_answer(cls, ans_id, answer):
     print("ans_id:", ans_id, " answer:", answer)
     handle = AnswerHandler()
     question = handle.update_answer(ans_id, answer)
     # print(question)
     if question:
         return True
     return False
Пример #4
0
 def add_answer(cls, answer):
     ''' this first checks if a question exists and if it does, it adds an answer to it
     True is returned for success and False when it fails to add the answer '''
     if Question.get_question_by_id(answer.qn_id):
         handle = AnswerHandler()
         pprint(answer.json())
         handle.insert_answer(answer.user_id, answer.qn_id, answer.answer)
         return True
     return False
Пример #5
0
 def get_answer_by_qn_id(cls, answerId, qn_id):
     ''' gets  '''
     handle = AnswerHandler()
     answer = handle.get_answer_by_qn_id(answerId, qn_id)
     print('printing answer...')
     print(answer)
     if answer:  # answer, qn_id, user_id, ans_id
         return Answer(answer["answer"], answer["qn_id"], answer["user_id"],
                       answer["ans_id"], answer["preferred"])
     return None
Пример #6
0
    def get_answers_by_qn_id(cls, qn_id):
        handle = AnswerHandler()
        answers = handle.get_answers_by_qn_id(qn_id)
        answersList = []
        if answers:
            for answer in answers:  # answer, qn_id, user_id, ans_id
                ans = Answer(answer['answer'], answer['qn_id'],
                             answer["user_id"], answer["ans_id"],
                             answer["preferred"])
                answersList.append(ans)

            # append comments....

            return [x.json() for x in answersList]
        return answersList
Пример #7
0
    def get_answers(cls):
        handle = AnswerHandler()
        answers = handle.get_answers()
        answersList = []
        if answers:
            for answer in answers:
                qn = Answer(answer['answer'], answer['qn_id'],
                            answer["user_id"], answer["ans_id"],
                            answer["preferred"])
                answersList.append(qn)

            return [x.json() for x in answersList]
        # from .answer import Answer
        # for qn in cls.questions:
        #     qn['answers'].extend(Answer.get_answers_by_qn_id(qn['id']))
        return answersList
Пример #8
0
 def check_repeated_ans(cls, answer, qn_id):
     ''' check if an answer has already been given '''
     handle = AnswerHandler()
     return handle.check_answer(answer, qn_id)