diff options
author | CruiseDevice | 2018-11-11 01:03:11 +0530 |
---|---|---|
committer | CruiseDevice | 2019-01-28 13:07:02 +0530 |
commit | ae5e8ca5eb5d47afb14ba83e665de6f10e46bdac (patch) | |
tree | 3a275aa025fc294dbee88fab3e354305378882c9 /yaksh/views.py | |
parent | 53e43a65f0b47557da035597f37b4ee9a9d5e290 (diff) | |
download | online_test-ae5e8ca5eb5d47afb14ba83e665de6f10e46bdac.tar.gz online_test-ae5e8ca5eb5d47afb14ba83e665de6f10e46bdac.tar.bz2 online_test-ae5e8ca5eb5d47afb14ba83e665de6f10e46bdac.zip |
Fix #525
- Categorize questions into objectives, blanks, upload and programming.
Diffstat (limited to 'yaksh/views.py')
-rw-r--r-- | yaksh/views.py | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/yaksh/views.py b/yaksh/views.py index 0f81931..af4eec1 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -561,6 +561,20 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, raise Http404(msg) +def _get_question_by_index(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(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 _get_question_by_index(all_ordered_questions, questions_by_type) + + @login_required @email_verified def show_question(request, question, paper, error_message=None, @@ -568,6 +582,7 @@ def show_question(request, question, paper, error_message=None, previous_question=None): """Show a question if possible.""" quiz = paper.question_paper.quiz + questions = paper.questions.all() quiz_type = 'Exam' can_skip = False if previous_question: @@ -616,6 +631,46 @@ def show_question(request, question, paper, error_message=None, 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 = {} + categories = {} + categories["objectives"] = questions.filter(Q(type="mcq") | + Q(type="mcc") | + Q(type="arrange")) + categories["blanks"] = questions.filter(Q(type="integer") | + Q(type="string") | + Q(type="float")) + categories["programming"] = questions.filter(Q(type="code")) + categories["upload"] = questions.filter(Q(type="upload")) + types["objective_types"] = set([type_.type + for type_ in categories["objectives"]]) + types["blank_types"] = set([type_.type + for type_ in categories["blanks"]]) + types["programming_types"] = set([type_.type + for type_ in categories["programming"]]) + types["upload_types"] = set([type_.type + for type_ in categories["upload"]]) + all_ordered_questions = paper.get_all_ordered_questions() + objectives_index = _get_questions_by_type( + all_ordered_questions, + types["objective_types"] + ) + blanks_index = _get_questions_by_type( + all_ordered_questions, + types["blank_types"] + ) + programming_index = _get_questions_by_type( + all_ordered_questions, + types["programming_types"] + ) + upload_index = _get_questions_by_type( + all_ordered_questions, + types["upload_types"] + ) + index = {} + index["objectives_index"] = objectives_index + index["blanks_index"] = blanks_index + index["programming_index"] = programming_index + index["upload_index"] = upload_index context = { 'question': question, 'paper': paper, @@ -631,7 +686,8 @@ 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 + "question_types": all_question_types, + "index": index, } answers = paper.get_previous_answers(question) if answers: |