From ae5e8ca5eb5d47afb14ba83e665de6f10e46bdac Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Sun, 11 Nov 2018 01:03:11 +0530 Subject: Fix #525 - Categorize questions into objectives, blanks, upload and programming. --- yaksh/views.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'yaksh/views.py') 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: -- cgit From f72b744db670d88c095200832a638b69f514f55c Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Thu, 3 Jan 2019 16:08:50 +0530 Subject: Code refactor - Move get_question_by_index() and get_question_by_type() from views.py to models.py . - Change variable names. --- yaksh/views.py | 74 +++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 40 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index af4eec1..4c23ba6 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -561,20 +561,6 @@ 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, @@ -632,45 +618,53 @@ def show_question(request, question, paper, error_message=None, 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"]]) + 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 = _get_questions_by_type( + + objectives_index = paper.get_questions_by_type( all_ordered_questions, types["objective_types"] ) - blanks_index = _get_questions_by_type( + blanks_index = paper.get_questions_by_type( all_ordered_questions, types["blank_types"] ) - programming_index = _get_questions_by_type( + programming_index = paper.get_questions_by_type( all_ordered_questions, types["programming_types"] ) - upload_index = _get_questions_by_type( + upload_index = paper.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 + + index = { + 'objectives_index': objectives_index, + 'blanks_index': blanks_index, + 'programming_index': programming_index, + 'upload_index': upload_index + } context = { 'question': question, 'paper': paper, -- cgit 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/views.py | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) (limited to 'yaksh/views.py') 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: -- cgit From 461cfcd6c736a016636932e019476558135f0ccf Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 14 Jan 2019 14:42:01 +0530 Subject: Remove unused variables and imports --- yaksh/views.py | 1 - 1 file changed, 1 deletion(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 3eaa165..68d2b8a 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -568,7 +568,6 @@ 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: -- cgit From 85427fceb1c06cf036f2351ebdc0a051b5d4acb6 Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 14 Jan 2019 15:24:48 +0530 Subject: Fix PEP8 errors in views.py --- yaksh/views.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index 68d2b8a..6c7a12e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -903,8 +903,10 @@ def complete(request, reason=None, attempt_num=None, questionpaper_id=None, """Show a page to inform user that the quiz has been completed.""" user = request.user if questionpaper_id is None: - message = (reason or "An Unexpected Error occurred. Please contact your" - " instructor/administrator.") + message = ( + reason or "An Unexpected Error occurred." + " Please contact your instructor/administrator." + ) context = {'message': message} return my_render_to_response(request, 'yaksh/complete.html', context) else: -- cgit