From 1bc499984dec2d6e89dc01e79622676917c63f0c Mon Sep 17 00:00:00 2001 From: ariannedee Date: Mon, 24 Aug 2020 15:54:37 -0700 Subject: [PATCH] Add function to return a dictionary of error fields --- edivorce/apps/core/utils/step_completeness.py | 17 ++++++++++++++++- edivorce/apps/core/utils/user_response.py | 2 +- edivorce/apps/core/views/main.py | 18 +++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/edivorce/apps/core/utils/step_completeness.py b/edivorce/apps/core/utils/step_completeness.py index 1142c6ab..17cdddf6 100644 --- a/edivorce/apps/core/utils/step_completeness.py +++ b/edivorce/apps/core/utils/step_completeness.py @@ -1,7 +1,7 @@ from django.urls import reverse from edivorce.apps.core.models import Question -from edivorce.apps.core.utils.question_step_mapping import pre_qual_step_question_mapping +from edivorce.apps.core.utils.question_step_mapping import page_step_mapping, pre_qual_step_question_mapping def evaluate_numeric_condition(target, reveal_response): @@ -32,6 +32,10 @@ def evaluate_numeric_condition(target, reveal_response): def get_step_completeness(responses_by_step): + """ + Accepts a dictionary of {step: {question_id: {question__name, question_id, value, error}}} <-- from get_step_responses + Returns {step: status}, {step: [missing_question_key]} + """ status_dict = {} missing_response_dict = {} for step, responses_list in responses_by_step.items(): @@ -73,3 +77,14 @@ def get_formatted_incomplete_list(missed_question_keys): 'step_url': reverse('prequalification', kwargs={'step': step}) }) return missed_questions + + +def get_error_dict(step, missing_questions): + """ + Returns a dict of {question_key_error: True} for any + """ + responses_dict = {} + question_step = page_step_mapping[step] + for question_dict in missing_questions.get(question_step): + responses_dict[question_dict['question_id'] + '_error'] = True + return responses_dict diff --git a/edivorce/apps/core/utils/user_response.py b/edivorce/apps/core/utils/user_response.py index ee1749a2..6ae69c4a 100644 --- a/edivorce/apps/core/utils/user_response.py +++ b/edivorce/apps/core/utils/user_response.py @@ -20,7 +20,7 @@ def get_data_for_user(bceid_user): def get_step_responses(responses_by_key): """ - Accepts a dictionary of {question_key: user_response_value} (from get_data_for_user) + Accepts a dictionary of {question_key: user_response_value} <-- from get_data_for_user Returns a dictionary of {step: {question_id: {question__name, question_id, value, error}}} """ responses_by_step = {} diff --git a/edivorce/apps/core/views/main.py b/edivorce/apps/core/views/main.py index b9584461..c2ace4e7 100644 --- a/edivorce/apps/core/views/main.py +++ b/edivorce/apps/core/views/main.py @@ -7,11 +7,11 @@ from django.utils import timezone from edivorce.apps.core.utils.derived import get_derived_data from ..decorators import bceid_required, intercept -from ..utils.question_step_mapping import list_of_registries, page_step_mapping -from ..utils.step_completeness import get_step_completeness, is_complete, get_formatted_incomplete_list +from ..utils.question_step_mapping import list_of_registries +from ..utils.step_completeness import get_error_dict, get_step_completeness, is_complete, get_formatted_incomplete_list from ..utils.template_step_order import template_step_order from ..utils.user_response import ( - get_data_for_user, + get_data_for_user, copy_session_to_db, get_step_responses, get_responses_from_session, @@ -196,10 +196,10 @@ def question(request, step, sub_step=None): template = 'question/%02d_%s%s.html' % (template_step_order[step], step, sub_page_template) if step == "review": - responses_dict = get_data_for_user(request.user) - responses_dict_by_step = get_step_responses(responses_dict) + data_dict = get_data_for_user(request.user) + responses_dict_by_step = get_step_responses(data_dict) step_status, missing_questions = get_step_completeness(responses_dict_by_step) - derived = get_derived_data(responses_dict) + derived = get_derived_data(data_dict) responses_dict = {} # Just for now (until showing missing questions in review is implemented) remove unanswered questions @@ -213,12 +213,8 @@ def question(request, step, sub_step=None): responses_dict = get_data_for_user(request.user) responses_dict_by_step = get_step_responses(responses_dict) step_status, missing_questions = get_step_completeness(responses_dict_by_step) - question_step = page_step_mapping.get(step, step) - show_errors = step_status.get(question_step) == 'Started' + responses_dict.update(get_error_dict(step, missing_questions)) derived = get_derived_data(responses_dict) - if show_errors: - for question_dict in missing_questions.get(question_step): - responses_dict[question_dict['question_id'] + '_error'] = True # Add step status dictionary responses_dict['step_status'] = step_status