Skip to content

Commit

Permalink
Merge pull request #646 from OpenSourcePolicyCenter/643_fiscal_table_…
Browse files Browse the repository at this point in the history
…enhancement

Add summary row for table
  • Loading branch information
brittainhard authored Sep 18, 2017
2 parents e66ac88 + 34fee15 commit cdf9503
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions webapp/apps/taxbrain/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,28 @@ def edit_personal_results(request, pk):
return render(request, 'taxbrain/input_form.html', init_context)


def add_summary_column(table):
import copy
summary = copy.deepcopy(table["cols"][-1])
summary["label"] = "Total"
table["cols"].append(summary)
table["col_labels"].append("Total")
for x in table["rows"]:
row_total = 0
for y in x["cells"]:
row_total += float(y["value"])
x["cells"].append({
'format': {
u'decimals': 1,
u'divisor': 1000000000
},
u'value': unicode(row_total),
u'year_values': {}
})
return table



def get_result_context(model, request, url):
output = model.tax_result
first_year = model.first_year
Expand Down Expand Up @@ -665,9 +687,9 @@ def get_result_context(model, request, url):
is_registered = True if request.user.is_authenticated() else False
else:
is_registered = False
tables['fiscal_change'] = tables['fiscal_tot_diffs']
tables['fiscal_currentlaw'] = tables['fiscal_tot_base']
tables['fiscal_reform'] = tables['fiscal_tot_ref']
tables['fiscal_change'] = add_summary_column(tables['fiscal_tot_diffs'])
tables['fiscal_currentlaw'] = add_summary_column(tables['fiscal_tot_base'])
tables['fiscal_reform'] = add_summary_column(tables['fiscal_tot_ref'])
json_table = json.dumps(tables)

context = {
Expand Down

0 comments on commit cdf9503

Please sign in to comment.