From 0e3353d489fd54a2c84c712ae04e44a9f8d8cd90 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Wed, 19 Dec 2018 13:46:40 +0530 Subject: Provide API version 1 for Yaksh - Serializers for Question, Quiz, QuestionPaper, AnswerPaper - Can create questions, quizzes, question and answer papers - Can check mcq, mcc and code questions - Tests for the API --- api/serializers.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 api/serializers.py (limited to 'api/serializers.py') diff --git a/api/serializers.py b/api/serializers.py new file mode 100644 index 0000000..919e429 --- /dev/null +++ b/api/serializers.py @@ -0,0 +1,25 @@ +from rest_framework import serializers +from yaksh.models import Question, Quiz, QuestionPaper, AnswerPaper + + +class QuestionSerializer(serializers.ModelSerializer): + class Meta: + model = Question + fields = '__all__' + + +class QuizSerializer(serializers.ModelSerializer): + class Meta: + model = Quiz + fields = '__all__' + + +class QuestionPaperSerializer(serializers.ModelSerializer): + class Meta: + model = QuestionPaper + fields = '__all__' + +class AnswerPaperSerializer(serializers.ModelSerializer): + class Meta: + model = AnswerPaper + fields = '__all__' -- cgit From 81d1e4e4ff4406f7f3823c40a82cf21096f2ccec Mon Sep 17 00:00:00 2001 From: prathamesh Date: Thu, 20 Dec 2018 10:53:23 +0530 Subject: Resolve PEP8 issues --- api/serializers.py | 1 + 1 file changed, 1 insertion(+) (limited to 'api/serializers.py') diff --git a/api/serializers.py b/api/serializers.py index 919e429..d34f269 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -19,6 +19,7 @@ class QuestionPaperSerializer(serializers.ModelSerializer): model = QuestionPaper fields = '__all__' + class AnswerPaperSerializer(serializers.ModelSerializer): class Meta: model = AnswerPaper -- cgit From a7b4b9e0c6699987d1dee4007e9c62da15559432 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Fri, 21 Jun 2019 03:23:45 +0530 Subject: Add API to get complete course details and AnswerPaper for the quiz Courses are retrieved in which the user is a student. Complete course info is made available. Answerpaper is created if does not exists on start quiz. AnswerPaper detail info is made available. If attempts are not allowed then the message is retrieved. --- api/serializers.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'api/serializers.py') diff --git a/api/serializers.py b/api/serializers.py index d34f269..df66730 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,5 +1,8 @@ from rest_framework import serializers -from yaksh.models import Question, Quiz, QuestionPaper, AnswerPaper +from yaksh.models import ( + Question, Quiz, QuestionPaper, AnswerPaper, Course, + LearningModule, LearningUnit, Lesson +) class QuestionSerializer(serializers.ModelSerializer): @@ -21,6 +24,43 @@ class QuestionPaperSerializer(serializers.ModelSerializer): class AnswerPaperSerializer(serializers.ModelSerializer): + + questions = QuestionSerializer(many=True) + class Meta: model = AnswerPaper fields = '__all__' + + +class LessonSerializer(serializers.ModelSerializer): + class Meta: + model = Lesson + fields = '__all__' + + +class LearningUnitSerializer(serializers.ModelSerializer): + + quiz = QuizSerializer() + lesson = LessonSerializer() + + class Meta: + model = LearningUnit + fields = '__all__' + + +class LearningModuleSerializer(serializers.ModelSerializer): + + learning_unit = LearningUnitSerializer(many=True) + + class Meta: + model = LearningModule + fields = '__all__' + + +class CourseSerializer(serializers.ModelSerializer): + + learning_module = LearningModuleSerializer(many=True) + + class Meta: + model = Course + fields = '__all__' -- cgit From 7d75a279112bce3969d2d4a2b70d74dd67570e29 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 30 Mar 2020 20:39:55 +0530 Subject: Show question test_cases, exclude unncessary fields from API --- api/serializers.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'api/serializers.py') diff --git a/api/serializers.py b/api/serializers.py index df66730..1c1e6a4 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -6,15 +6,21 @@ from yaksh.models import ( class QuestionSerializer(serializers.ModelSerializer): + test_cases = serializers.SerializerMethodField() + + def get_test_cases(self, obj): + test_cases = obj.get_test_cases_as_dict() + return test_cases + class Meta: model = Question - fields = '__all__' + exclude = ('partial_grading', ) class QuizSerializer(serializers.ModelSerializer): class Meta: model = Quiz - fields = '__all__' + exclude = ('view_answerpaper', ) class QuestionPaperSerializer(serializers.ModelSerializer): @@ -63,4 +69,11 @@ class CourseSerializer(serializers.ModelSerializer): class Meta: model = Course - fields = '__all__' + exclude = ( + 'teachers', + 'rejected', + 'requests', + 'students', + 'grading_system', + 'view_grade', + ) -- cgit