diff options
author | CruiseDevice | 2019-01-04 16:33:26 +0530 |
---|---|---|
committer | CruiseDevice | 2019-01-28 13:07:02 +0530 |
commit | a4c6a0a3c013f02c7cdd1d365a180ff6de121d6e (patch) | |
tree | 83055ac859ae88740790197fbf8db01352bbd1e9 /yaksh | |
parent | f72b744db670d88c095200832a638b69f514f55c (diff) | |
download | online_test-a4c6a0a3c013f02c7cdd1d365a180ff6de121d6e.tar.gz online_test-a4c6a0a3c013f02c7cdd1d365a180ff6de121d6e.tar.bz2 online_test-a4c6a0a3c013f02c7cdd1d365a180ff6de121d6e.zip |
Code refactor and resolves requested changes.
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 36 | ||||
-rw-r--r-- | yaksh/static/yaksh/css/exam.css | 3 | ||||
-rw-r--r-- | yaksh/templates/exam.html | 40 | ||||
-rw-r--r-- | yaksh/views.py | 51 |
4 files changed, 28 insertions, 102 deletions
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 @@ <p class="text-center">Question(s) left: <b>{{ paper.questions_left }}</b></p> </div> <br> - <table class = "table table-bordered table-sm"> + <table class = "legend_table table-bordered table-sm"> <thead> <tr> <th>Category</th> @@ -86,46 +86,16 @@ </tr> </thead> <tbody> - {% if index.objectives_index %} + {% for category, question_number in paper.get_categorized_question_indices.items %} <tr> <td> - Objectives: + {{category}} </td> <td> - {{index.objectives_index|join:", "}} + {{question_number| join:", "}} </td> </tr> - {% endif %} - {% if index.blanks_index %} - <tr> - <td> - Blanks: - </td> - <td> - {{index.blanks_index|join:", "}} - </td> - </tr> - {% endif %} - {% if index.upload_index %} - <tr> - <td> - Upload: - </td> - <td> - {{index.upload_index|join:", "}} - </td> - </tr> - {% endif %} - {% if index.programming_index %} - <tr> - <td> - Programming: - </td> - <td> - {{index.programming_index|join:", "}} - </td> - </tr> - {% endif %} + {% endfor %} </tbody> </table> </div> <!--end of sidebar --> diff --git a/yaksh/views.py b/yaksh/views.py index 4c23ba6..3eaa165 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -616,55 +616,6 @@ def show_question(request, question, paper, error_message=None, course = Course.objects.get(id=course_id) module = course.learning_module.get(id=module_id) all_modules = course.get_learning_modules() - all_question_types = [types[0] for types in question_types] - types = {} - categorized_questions = {} - categorized_questions["objectives"] = questions.filter(Q(type="mcq") | - Q(type="mcc") | - Q(type="arrange")) - categorized_questions["blanks"] = questions.filter(Q(type="integer") | - Q(type="string") | - Q(type="float")) - categorized_questions["programming"] = questions.filter(Q(type="code")) - categorized_questions["upload"] = questions.filter(Q(type="upload")) - - types["objective_types"] = set([_type.type - for _type in - categorized_questions["objectives"]]) - types["blank_types"] = set([_type.type - for _type in - categorized_questions["blanks"]]) - types["programming_types"] = set([_type.type - for _type in - categorized_questions["programming"]]) - types["upload_types"] = set([_type.type - for _type in categorized_questions["upload"]]) - - all_ordered_questions = paper.get_all_ordered_questions() - - objectives_index = paper.get_questions_by_type( - all_ordered_questions, - types["objective_types"] - ) - blanks_index = paper.get_questions_by_type( - all_ordered_questions, - types["blank_types"] - ) - programming_index = paper.get_questions_by_type( - all_ordered_questions, - types["programming_types"] - ) - upload_index = paper.get_questions_by_type( - all_ordered_questions, - types["upload_types"] - ) - - index = { - 'objectives_index': objectives_index, - 'blanks_index': blanks_index, - 'programming_index': programming_index, - 'upload_index': upload_index - } context = { 'question': question, 'paper': paper, @@ -680,8 +631,6 @@ def show_question(request, question, paper, error_message=None, 'delay_time': delay_time, 'quiz_type': quiz_type, 'all_modules': all_modules, - "question_types": all_question_types, - "index": index, } answers = paper.get_previous_answers(question) if answers: |