Browse Source

Fixing bug on review screen where was not showing children related information

pull/160/head
Benard Ebinu 8 years ago
parent
commit
2cee916258
3 changed files with 42 additions and 33 deletions
  1. +11
    -7
      edivorce/apps/core/templatetags/summary_format.py
  2. +25
    -25
      edivorce/apps/core/utils/step_completeness.py
  3. +6
    -1
      edivorce/apps/core/utils/user_response.py

+ 11
- 7
edivorce/apps/core/templatetags/summary_format.py View File

@ -226,7 +226,7 @@ def prequal_tag(source):
end_tag = '</td></tr>'
marriage_status = lived_in_bc = live_at_least_year = separation_date = try_reconcile = reconciliation_period = None
children_of_marriage = any_under_19 = financial_support = certificate = provide_later = None
children_of_marriage = number_children_under_19 = number_children_over_19 = financial_support = certificate = provide_later = None
provide_later_reason = not_provide_later_reason = in_english = divorce_reason = None
for item in source:
@ -245,8 +245,10 @@ def prequal_tag(source):
reconciliation_period = item
elif q_id == 'children_of_marriage':
children_of_marriage = item
elif q_id == 'any_under_19':
any_under_19 = item
elif q_id == 'number_children_under_19':
number_children_under_19 = item
elif q_id == 'number_children_over_19':
number_children_over_19 = item
elif q_id == 'children_financial_support':
financial_support = item
elif q_id == 'original_marriage_certificate':
@ -278,10 +280,12 @@ def prequal_tag(source):
tags.append(first_column + reconciliation_period['question__name'] + second_column + reconciliation_period_reformat(reconciliation_period['value']) + end_tag)
if children_of_marriage:
tags.append(first_column + children_of_marriage['question__name'] + second_column + children_of_marriage['value'] + end_tag)
if children_of_marriage and children_of_marriage['value'] == 'YES' and any_under_19:
tags.append(first_column + any_under_19['question__name'] + second_column + any_under_19['value'] + end_tag)
if children_of_marriage and children_of_marriage['value'] == 'YES' and any_under_19['value'] == 'NO' and financial_support:
tags.append(first_column + financial_support['question__name'] + second_column + json.loads(financial_support['value'])[0] + end_tag)
if children_of_marriage and children_of_marriage['value'] == 'YES' and number_children_under_19:
tags.append(first_column + number_children_under_19['question__name'] + second_column + number_children_under_19['value'] + end_tag)
if children_of_marriage and children_of_marriage['value'] == 'YES' and number_children_over_19:
tags.append(first_column + number_children_over_19['question__name'] + second_column + number_children_over_19['value'] + end_tag)
if children_of_marriage and children_of_marriage['value'] == 'YES' and number_children_over_19 and financial_support and financial_support['value']:
tags.append(first_column + financial_support['question__name'] + second_column + '.'.join(json.loads(financial_support['value'])) + end_tag)
if certificate:
tags.append(first_column + certificate['question__name'] + second_column + certificate['value'] + end_tag)
if certificate and certificate['value'] == 'NO' and provide_later:


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

@ -2,6 +2,30 @@ from edivorce.apps.core.models import Question
from edivorce.apps.core.utils.question_step_mapping import question_step_mapping
def evaluate_numeric_condition(target, reveal_response):
"""
Tests whether the reveal_response contains a numeric condition. If so, it will
evaluate the numeric condition and return the results of that comparison.
:param target: the questions value being tested against
:param reveal_response: the numeric condition that will be evaluated against
:return: boolean result of numeric condition evaluation or None if there is no
numeric condition to evaluate.
"""
if reveal_response.startswith('>='):
return int(target) >= int(reveal_response[2:])
elif reveal_response.startswith('<='):
return int(target) <= int(reveal_response[2:])
elif reveal_response.startswith('=='):
return int(target) == int(reveal_response[2:])
elif reveal_response.startswith('<'):
return int(target) < int(reveal_response[1:])
elif reveal_response.startswith('>'):
return int(target) > int(reveal_response[1:])
else:
return None
def get_step_status(responses_by_step):
status_dict = {}
for step, lst in responses_by_step.items():
@ -52,7 +76,7 @@ def is_complete(step, lst):
def __condition_met(reveal_response, target, lst):
# check whether using a numeric condition
numeric_condition_met = __evaluate_numeric_condition(target, reveal_response)
numeric_condition_met = evaluate_numeric_condition(target["value"], reveal_response)
if numeric_condition_met is None:
if target["value"] != reveal_response:
return False
@ -83,27 +107,3 @@ def __has_value(key, lst):
if answer != "" and answer != "[]" and answer != '[["",""]]':
return True
return False
def __evaluate_numeric_condition(target, reveal_response):
"""
Tests whether the reveal_response contains a numeric condition. If so, it will
evaluate the numeric condition and return the results of that comparison.
:param target: the questions value being tested against
:param reveal_response: the numeric condition that will be evaluated against
:return: boolean result of numeric condition evaluation or None if there is no
numeric condition to evaluate.
"""
if reveal_response.startswith('>='):
return int(target["value"]) >= int(reveal_response[2:])
elif reveal_response.startswith('<='):
return int(target["value"]) <= int(reveal_response[2:])
elif reveal_response.startswith('=='):
return int(target["value"]) == int(reveal_response[2:])
elif reveal_response.startswith('<'):
return int(target["value"]) < int(reveal_response[1:])
elif reveal_response.startswith('>'):
return int(target["value"]) > int(reveal_response[1:])
else:
return None

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

@ -1,5 +1,6 @@
from edivorce.apps.core.models import UserResponse, Question
from edivorce.apps.core.utils.question_step_mapping import question_step_mapping
from edivorce.apps.core.utils.step_completeness import evaluate_numeric_condition
def get_responses_from_db(bceid_user):
@ -56,7 +57,11 @@ def get_responses_from_db_grouped_by_steps(bceid_user, hide_failed_conditionals=
target = q['question__conditional_target']
if target not in values:
continue
if q['question__reveal_response'] != values[target]:
numeric_condition = evaluate_numeric_condition(values[target], q['question__reveal_response'])
if numeric_condition is None:
if q['question__reveal_response'] != values[target]:
q['value'] = ''
elif numeric_condition is False:
q['value'] = ''
responses_dict[step] = lst


Loading…
Cancel
Save