summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCruiseDevice2020-03-30 20:39:55 +0530
committerCruiseDevice2020-03-30 20:39:55 +0530
commit7d75a279112bce3969d2d4a2b70d74dd67570e29 (patch)
treec55c75765f4177f4afa11627091ff4cb17bcd950
parentc3a18de3b8f120b16dea005d2b0ce375804f24ec (diff)
downloadonline_test-7d75a279112bce3969d2d4a2b70d74dd67570e29.tar.gz
online_test-7d75a279112bce3969d2d4a2b70d74dd67570e29.tar.bz2
online_test-7d75a279112bce3969d2d4a2b70d74dd67570e29.zip
Show question test_cases, exclude unncessary fields from API
-rw-r--r--api/serializers.py19
-rw-r--r--yaksh/models.py13
2 files changed, 29 insertions, 3 deletions
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',
+ )
diff --git a/yaksh/models.py b/yaksh/models.py
index 949b87e..813453d 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1426,6 +1426,19 @@ class Question(models.Model):
tc_list.extend(test_case)
return tc_list
+ def get_test_cases_as_dict(self, **kwargs):
+ tc_list = []
+ for tc in self.testcase_set.values_list("type", flat=True).distinct():
+ test_case_ctype = ContentType.objects.get(app_label="yaksh",
+ model=tc)
+ test_case = test_case_ctype.get_all_objects_for_this_type(
+ question=self,
+ **kwargs
+ )
+ for tc in test_case:
+ tc_list.append(model_to_dict(tc))
+ return tc_list
+
def get_test_case(self, **kwargs):
for tc in self.testcase_set.all():
test_case_type = tc.type