def put(self, id, answer_id): '''Accept an answer and update an answer''' question = Question.get_by_id(id=id) logged_in_user = get_jwt_identity() answer_to_update = Answer.get_by_id(answer_id) print(answer_to_update) if question: if answer_to_update: if answer_to_update['user_id'] == logged_in_user: parser = reqparse.RequestParser() parser.add_argument('body', help='The body field cannot be blank', required=True, type=str) parser.parse_args() answer_to_update = Answer.update(id=answer_id, body=request.json['body'], user_id=get_jwt_identity(), accept=False) return {"message": "You have successfully updated the answer", "data": answer_to_update}, 201 if question['user']["id"] == logged_in_user and answer_to_update['question_id'] == question["id"]: if Validate.check_answer_accepted(question_id=question["id"]): return {"message": "The question has an already acceped answer"}, 405 Answer.accept(id=answer_id) return {"message": "You have successfully accepted the answer"}, 201 else: return {"message": "You are not authorized to modify the answer"}, 401 return {"message": "Answer not found"}, 404 return {"message": "No question found with that answer"}, 404