From a4c6a0a3c013f02c7cdd1d365a180ff6de121d6e Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Fri, 4 Jan 2019 16:33:26 +0530 Subject: Code refactor and resolves requested changes. --- yaksh/models.py | 36 +++++++++++++++++------------ yaksh/static/yaksh/css/exam.css | 3 ++- yaksh/templates/exam.html | 40 ++++---------------------------- yaksh/views.py | 51 ----------------------------------------- 4 files changed, 28 insertions(+), 102 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 98a63b0..0f20605 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": {"category": "objective", "label": "Objective Type"}, + "mcc": {"category": "objective", "label": "Objective Type"}, + "code": {"category": "programming", "label": "Programming"}, + "upload": {"category": "upload", "label": "Upload"}, + "integer": {"category": "objective", "label": "Objective Type"}, + "string": {"category": "objective", "label": "Objective Type"}, + "float": {"category": "objective", "label": "Objective Type"}, + "arrange": {"category": "objective", "label": "Objective Type"}, + } + attempts = [(i, i) for i in range(1, 6)] attempts.append((-1, 'Infinite')) @@ -2091,20 +2103,14 @@ class AnswerPaper(models.Model): def get_previous_answers(self, question): return self.answers.filter(question=question).order_by('-id') - def get_question_by_index(self, all_ordered_questions, questions_by_type): - return [index+1 for index, item in enumerate(all_ordered_questions) - if item in set(questions_by_type)] - - def get_questions_by_type(self, all_ordered_questions, objective_types): - questions_by_type = [] - for types in objective_types: - for question in all_ordered_questions: - if question.type == types: - questions_by_type.append(question) - return self.get_question_by_index( - all_ordered_questions, - questions_by_type - ) + def get_categorized_question_indices(self): + + category_question_map = defaultdict(lambda: []) + for index, question in enumerate(self.get_all_ordered_questions(), 1): + category_question_map[ + legend_display_types[question.type]["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): diff --git a/yaksh/static/yaksh/css/exam.css b/yaksh/static/yaksh/css/exam.css index e420166..a246141 100644 --- a/yaksh/static/yaksh/css/exam.css +++ b/yaksh/static/yaksh/css/exam.css @@ -5,8 +5,9 @@ #stdio, #assertion { table-layout: fixed } -.table{ +.legend_table{ border: 1px solid; + width: 15em; background-color: white; border-spacing: 5px; border-collapse: collapse; diff --git a/yaksh/templates/exam.html b/yaksh/templates/exam.html index 8c65e2b..29ad167 100644 --- a/yaksh/templates/exam.html +++ b/yaksh/templates/exam.html @@ -78,7 +78,7 @@
Question(s) left: {{ paper.questions_left }}
Category | @@ -86,46 +86,16 @@|
---|---|
- Objectives: + {{category}} | - {{index.objectives_index|join:", "}} + {{question_number| join:", "}} |
- Blanks: - | -- {{index.blanks_index|join:", "}} - | -
- Upload: - | -- {{index.upload_index|join:", "}} - | -
- Programming: - | -- {{index.programming_index|join:", "}} - | -