def validate(self,data): answer=data.get("answer",None) player=self.context.get("player") print(player) #player=data.get("player") active=config.quiz_active(config) day=config.objects.all()[0].current_day curr_question=player[0].current_question question=Question.objects.filter(day=day,question_no=curr_question) result=Question.check_ans(Question,answer,question) if result: player[0].new_score(player) return { "result":result }
def validate(self,data): answer=data.get("answer",None) player=self.context.get("player") print(player) #player=data.get("player") active=config.quiz_active(config) curr_config = config.current_config(config) day=curr_config.current_day curr_question=player[0].current_question question=Question.objects.filter(day=day,question_no=curr_question) result=Question.check_ans(Question,answer,question) #answer is being checked here. Resulting response is sent back if result: player[0].new_score(player) #if ans is correct, new score is store. Result is returned return { "result":result }
def post(self, request): player = UserScore.objects.filter(user=request.user)[0] print(player.name) answer = request.data.get("answer", None) print(player) active = config.quiz_active(config) curr_config = config.current_config(config) if active: day = curr_config.current_day curr_day = player.today curr_question = player.current_question if curr_day > day: response = {"quiz_finished": True} return Response(response) if curr_day < day: player.today = day player.current_question = 1 curr_day = player.today curr_question = player.current_question player.save() question = Question.objects.filter(day=day, question_no=curr_question) result = Question.check_ans(Question, answer, question) quiz_ended = False if result: player.new_score(player) UserScore.lboardSave(UserScore) curr_day = player.today if curr_day > curr_config.current_day: quiz_ended = True response = { 'status_code': status.HTTP_200_OK, 'result': result, 'quiz_finished': quiz_ended } else: response = {"error": "quiz has ended"} return Response(response)