def all_questions(request, user_id): """ Either get all questions under each quiz and category or get questions under specifc quiz and category. """ if request.query_params.get('subCategoryId'): logger.info('under quiz.all_questions') try: subcategory_id = request.query_params.get('subCategoryId') except SubCategory.DoesNotExist as e: logger.error('under quiz.all_questions '+str(e.args)) return Response({'errors': 'Questions not found'}, status=status.HTTP_404_NOT_FOUND) if request.query_params.get('questionFormat'): result = get_questions_format(user_id, subcategory_id, True) result['level'] = [] result['que_type'] = [] result['duration'] = 0 result['no_questions'] = 0 result['correct_grade'] = 1 result['incorrect_grade'] = 0 if result['questions_type_info']['mcq'][3] != 0: result['que_type'].append('mcq') if result['questions_type_info']['comprehension'][3] != 0: result['que_type'].append('comprehension') result['section_name'] = '1' result['subcategory_id'] = subcategory_id result = [result] # Must be a list else: result = get_questions_format(user_id, subcategory_id) else: result = get_questions_format(user_id) return Response(result, status = status.HTTP_200_OK)
def all_questions_under_subcategory(request, user_id, subcategory_id): """ Either get all questions under specific subcategory. If questionFormat is True --> Then we also uses answers and options for each question in JSON. Otherwise, we ignore them. """ if verify_user_hash(user_id, request.query_params.get('hash')): logger.info('under quiz.all_questions_under_subcategory') try: if not checkIfTrue(request.query_params.get('questionFormat')): quizzes = get_questions_format(user_id, subcategory_id, True) else: quizzes = get_questions_format(user_id, subcategory_id) return Response(quizzes, status = status.HTTP_200_OK) except SubCategory.DoesNotExist as e: logger.error('under quiz.all_questions_under_subcategory '+str(e.args)) return Response({'errors': 'Questions not found'}, status = status.HTTP_404_NOT_FOUND) logger.error('under quiz.all_questions_under_subcategory wrong hash') return Response({'errors': 'Corrupted User.'}, status=status.HTTP_404_NOT_FOUND)
def all_questions_under_category(request, userid, quizid, categoryid): """ Get all questions under a quiz and a category. """ try: quiz = Quiz.objects.get(id=quizid, user=userid) quizzes = get_questions_format(quiz, Category, SubCategory, Question, Answer) return Response(quizzes, status = status.HTTP_200_OK) except SubCategory.DoesNotExist as e: print e.args return Response({'errors': 'Questions not found'}, status=status.HTTP_404_NOT_FOUND)