Browse Source

DIV-724: programmatically displaying fact sheet e if precondition is met

pull/160/head
Benard Ebinu 7 years ago
parent
commit
2acdce8e28
3 changed files with 148 additions and 53 deletions
  1. +139
    -52
      edivorce/apps/core/templatetags/summary_format.py
  2. +7
    -1
      edivorce/apps/core/utils/question_step_mapping.py
  3. +2
    -0
      edivorce/apps/core/views/main.py

+ 139
- 52
edivorce/apps/core/templatetags/summary_format.py View File

@ -1,3 +1,5 @@
from collections import OrderedDict
from django import template
import json
@ -38,7 +40,7 @@ def process_list(lst, question_key):
else:
for value in lst:
if value and not value.isspace():
tag.append('<li>' + value + '</li>')
tag.append('<li>' + str(value) + '</li>')
tag.append('</ul>')
return ''.join(tag)
@ -49,68 +51,153 @@ def format_row(question, response):
)
@register.simple_tag
def format_children(source):
def format_head(headings):
if len(headings) == 0:
return '', []
tags = ["<tr>"]
head_order = list()
for key in headings[0].keys():
tags.append('<th>{}</th>'.format(key.replace('_', ' ').title()))
head_order.append(key)
tags.append('</tr>')
return ''.join(tags), head_order
def process_fact_sheet_list(data, header):
tags = list()
for item in data:
tags.append('<tr>')
for key in header:
tags.append('<td>{}</td>'.format(item.get(key, '')))
tags.append('</tr>')
return ''.join(tags)
def format_fact_sheet(title, responses):
if len(responses) == 0:
return ''
tags = ['<tr><td colspan="2">']
tags.append('<h3>{}</h3>'.format(title))
for response in responses:
value = response['value']
try:
value = json.loads(response['value'])
except:
pass
if isinstance(value, list):
thead, header = format_head(value)
tags.append("""
<p></p>
<p><strong>{0}</strong></p>
<table class="table table-bordered table-striped">
<thead>
{1}
</thead>
<tbody>
""".format(response['question__name'], thead))
tags.append(process_fact_sheet_list(value, header))
tags.append("""
</tbody>
</table>
""")
tags.append('</td></tr>')
return ''.join(tags)
@register.simple_tag(takes_context=True)
def format_children(context, source):
"""
:param source:
:return:
"""
question_to_heading = {
'Your Children': {
'claimant_children'
},
'What are you asking for?': {
'have_separation_agreement',
'have_court_order',
'order_respecting_arrangement',
'order_for_child_support',
'child_support_act'
},
'Income & expenses': {
'how_will_calculate_income',
'annual_gross_income',
'spouse_annual_gross_income'
},
'Are you or your spouse claiming undue hardship?': {
'special_extraordinary_expenses'
},
'Payor & medical expenses': {
'child_support_payor',
'claimants_agree_to_child_support_amount',
'medical_coverage_available',
'child_support_payments_in_arrears'
},
'Other fact sheets': {
}
}
question_to_heading = OrderedDict()
question_to_heading['Your Children'] = [
'claimant_children'
]
question_to_heading['What are you asking for?'] = [
'have_separation_agreement',
'have_court_order',
'order_respecting_arrangement',
'order_for_child_support',
'child_support_act'
]
question_to_heading['Income & expenses'] = [
'how_will_calculate_income',
'annual_gross_income',
'spouse_annual_gross_income'
]
question_to_heading['Are you or your spouse claiming undue hardship?'] = [
'special_extraordinary_expenses',
'claiming_undue_hardship',
'Undue Hardship (Fact Sheet E)'
]
question_to_heading['Payor & medical expenses'] = [
'child_support_payor',
'claimants_agree_to_child_support_amount',
'medical_coverage_available',
'child_support_payments_in_arrears'
]
question_to_heading['Other fact sheets'] = [
]
fact_sheet_mapping = OrderedDict()
fact_sheet_mapping['Undue Hardship (Fact Sheet E)'] = [
'claimant_debts',
'claimant_expenses',
'supporting_non_dependents',
'supporting_dependents',
'supporting_disabled',
'undue_hardship',
'income_others',
'total_income_others',
]
tags = []
# process mapped questions first
working_source = source.copy()
for title, questions in question_to_heading.items():
tags.append(format_row('<strong>{}</strong>'.format(title), ''))
for item in working_source:
q_id = item['question_id']
if q_id in questions:
if q_id == 'claimant_children':
for child in json.loads(item['value']):
tags.append(format_row('Child\'s name', child['child_name']))
tags.append(format_row('Birth date', child['child_birth_date']))
tags.append(format_row('Child living with', child['child_live_with']))
tags.append(format_row('Relationship to yourself (claimant 1)', child['child_relationship_to_you']))
tags.append(format_row('Relationship to your spouse (claimant 2)', child['child_relationship_to_spouse']))
else:
value = item['value']
try:
value = json.loads(item['value'])
except:
pass
if isinstance(value, list):
tags.append(format_row(item['question__name'], process_list(value, q_id)))
else:
tags.append(format_row(item['question__name'], value))
for question in questions:
if question in fact_sheet_mapping:
show_fact_sheet = False
if question == 'Undue Hardship (Fact Sheet E)' and context['derived']['show_fact_sheet_e']:
show_fact_sheet = True
if show_fact_sheet:
responses = list(filter(lambda x: x['question_id'] in fact_sheet_mapping[question], working_source))
tags.append(format_fact_sheet(question, responses))
else:
item = list(filter(lambda x: x['question_id'] == question, working_source))
if len(item):
item = item.pop()
q_id = item['question_id']
if q_id in questions:
if q_id == 'claimant_children':
for child in json.loads(item['value']):
tags.append(format_row('Child\'s name', child['child_name']))
tags.append(format_row('Birth date', child['child_birth_date']))
tags.append(format_row('Child living with', child['child_live_with']))
tags.append(format_row('Relationship to yourself (claimant 1)', child['child_relationship_to_you']))
tags.append(format_row('Relationship to your spouse (claimant 2)', child['child_relationship_to_spouse']))
else:
value = item['value']
try:
value = json.loads(item['value'])
except:
pass
if isinstance(value, list):
tags.append(format_row(item['question__name'], process_list(value, q_id)))
else:
tags.append(format_row(item['question__name'], value))
return ''.join(tags)


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

@ -101,7 +101,13 @@ question_step_mapping = {
'you_spouse_entered_agreement',
'claiming_undue_hardship',
'claimant_debts',
'claimant_expenses'
'claimant_expenses',
'supporting_non_dependents',
'supporting_dependents',
'supporting_disabled',
'undue_hardship',
'income_others',
'total_income_others',
],
'spousal_support': ['spouse_support_details', 'spouse_support_act'],
'property_and_debt': ['deal_with_property_debt',


+ 2
- 0
edivorce/apps/core/views/main.py View File

@ -5,6 +5,7 @@ from django.shortcuts import render, redirect, render_to_response
from django.utils import timezone
from django.template import RequestContext
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
from ..utils.step_completeness import get_step_status, is_complete, get_formatted_incomplete_list
@ -193,6 +194,7 @@ def question(request, step, sub_step=None):
responses_dict['registries'] = sorted(list_of_registries)
responses_dict['sub_step'] = sub_step
responses_dict['derived'] = get_derived_data(get_responses_from_db(request.user))
return render(request, template_name=template, context=responses_dict)


Loading…
Cancel
Save