Browse Source

Add function to return a dictionary of error fields

pull/160/head
ariannedee 5 years ago
parent
commit
1bc499984d
3 changed files with 24 additions and 13 deletions
  1. +16
    -1
      edivorce/apps/core/utils/step_completeness.py
  2. +1
    -1
      edivorce/apps/core/utils/user_response.py
  3. +7
    -11
      edivorce/apps/core/views/main.py

+ 16
- 1
edivorce/apps/core/utils/step_completeness.py View File

@ -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

+ 1
- 1
edivorce/apps/core/utils/user_response.py View File

@ -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 = {}


+ 7
- 11
edivorce/apps/core/views/main.py View File

@ -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


Loading…
Cancel
Save