diff options
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 427b584..cce90e7 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -6,7 +6,8 @@ import ruamel.yaml from ruamel.yaml.scalarstring import PreservedScalarString from ruamel.yaml.comments import CommentedMap from random import sample -from collections import Counter +from collections import Counter, defaultdict + from django.db import models from django.contrib.auth.models import User, Group, Permission from django.contrib.contenttypes.models import ContentType @@ -80,6 +81,17 @@ string_check_type = ( ("exact", "Case Sensitive"), ) +legend_display_types = { + "mcq": {"label": "Objective Type"}, + "mcc": {"label": "Objective Type"}, + "code": {"label": "Programming"}, + "upload": {"label": "Upload"}, + "integer": {"label": "Objective Type"}, + "string": {"label": "Objective Type"}, + "float": {"label": "Objective Type"}, + "arrange": {"label": "Objective Type"}, + } + attempts = [(i, i) for i in range(1, 6)] attempts.append((-1, 'Infinite')) @@ -2091,6 +2103,16 @@ class AnswerPaper(models.Model): def get_previous_answers(self, question): return self.answers.filter(question=question).order_by('-id') + def get_categorized_question_indices(self): + category_question_map = defaultdict(list) + for index, question in enumerate(self.get_all_ordered_questions(), 1): + question_category = legend_display_types.get(question.type) + if question_category: + category_question_map[ + question_category["label"] + ].append(index) + return dict(category_question_map) + def validate_answer(self, user_answer, question, json_data=None, uid=None, server_port=SERVER_POOL_PORT): """ |