From 441601329a17a935a54b058a00d55b08c5c27c90 Mon Sep 17 00:00:00 2001 From: Mike Olund Date: Mon, 27 Mar 2017 17:10:10 -0700 Subject: [PATCH] Hide married questions from review screen and pdf forms for unmarried claimants --- edivorce/apps/core/utils/user_response.py | 54 +++++++++++++++++++---- edivorce/fixtures/Question.json | 9 ++-- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/edivorce/apps/core/utils/user_response.py b/edivorce/apps/core/utils/user_response.py index 11a53b57..ce4166a4 100644 --- a/edivorce/apps/core/utils/user_response.py +++ b/edivorce/apps/core/utils/user_response.py @@ -1,25 +1,45 @@ from edivorce.apps.core.models import UserResponse, Question from edivorce.apps.core.utils.question_step_mapping import question_step_mapping - def get_responses_from_db(bceid_user): - responses = UserResponse.objects.filter(bceid_user=bceid_user) + """ Get UserResponses from the database for a user. """ + married, married_questions, responses = __get_data(bceid_user) responses_dict = {} for answer in responses: - responses_dict[answer.question.key] = answer.value + if not married and answer.question_id in married_questions: + responses_dict[answer.question.key] = '' + else: + responses_dict[answer.question.key] = answer.value + return responses_dict def get_responses_from_db_grouped_by_steps(bceid_user): """ Group questions and responses by steps they belong to """ - responses = UserResponse.objects.filter(bceid_user=bceid_user) + married, married_questions, responses = __get_data(bceid_user) responses_dict = {} + for step, questions in question_step_mapping.items(): - responses_dict[step] = responses.filter(question_id__in=questions).exclude( - value__in=['', '[]', '[["",""]]']).order_by('question').values('question_id', 'value', 'question__name', - 'question__required', - 'question__conditional_target', - 'question__reveal_response') + + lst = [] + step_responses = responses.filter(question_id__in=questions).exclude( + value__in=['', '[]', '[["",""]]']).order_by('question') + + for answer in step_responses: + if not married and answer.question_id in married_questions: + value = '' + else: + value = answer.value + + lst += [{'question__conditional_target': answer.question.conditional_target, + 'question__reveal_response': answer.question.reveal_response, + 'value': value, + 'question__name': answer.question.name, + 'question__required': answer.question.required, + 'question_id': answer.question.pk}] + + responses_dict[step] = lst + return responses_dict @@ -75,3 +95,19 @@ def copy_session_to_db(request, bceid_user): # clear the response from the session request.session[q.key] = None + + +def __get_data(bceid_user): + """ + Gets UserResponses from the database for a user, plus a boolean indicating + if the user is married or common-law, and a list of questions that only apply to + married couples + """ + COMMON_LAW = 'Living together in a marriage like relationship' + MARRIED = 'Legally married' + + responses = UserResponse.objects.filter(bceid_user=bceid_user) + married = responses.get(question_id='married_marriage_like').value != COMMON_LAW + married_questions = list( + Question.objects.filter(reveal_response=MARRIED).values_list("key", flat=True)) + return married, married_questions, responses diff --git a/edivorce/fixtures/Question.json b/edivorce/fixtures/Question.json index e513a1ac..30591947 100644 --- a/edivorce/fixtures/Question.json +++ b/edivorce/fixtures/Question.json @@ -418,8 +418,8 @@ "description": "For step 4, Form 1 2. Divorce section A", "summary_order": 39, "required": "Conditional", - "conditional_target": "where_were_you_married_other_country", - "reveal_response": "Other" + "conditional_target": "married_marriage_like", + "reveal_response": "Legally married" }, "model": "core.question", "pk": "where_were_you_married_country" @@ -428,7 +428,10 @@ "fields": { "name": "Where were you married? Other Country", "description": "For step 4, Form 1 2. Divorce section A", - "summary_order": 40 + "summary_order": 40, + "required": "Conditional", + "conditional_target": "where_were_you_married_country", + "reveal_response": "Other" }, "model": "core.question", "pk": "where_were_you_married_other_country"