Merge pull request #876 from Benbb96/0.2.x-dev

Display a Total row in Reports
This commit is contained in:
Garret Wassermann 2020-10-08 01:22:33 -04:00 committed by GitHub
commit 8fbebb321e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -75,6 +75,10 @@
{% for d in data %}<tr class='row_{% cycle 'odd' 'even' %}'>
{% for f in d %}<td class='report'>{{ f }}</td>{% endfor %}
</tr>{% endfor %}
{# Total row #}
<tr>
{% for f in total_data %}<td class='report'>{{ f }}</td>{% endfor %}
</tr>
</tbody>
</table>
</div>

View File

@ -1309,11 +1309,17 @@ def run_report(request, report):
column_headings = [col1heading] + possible_options
# Prepare a dict to store totals for each possible option
totals = {}
# Pivot the data so that 'header1' fields are always first column
# in the row, and 'possible_options' are always the 2nd - nth columns.
for item in header1:
data = []
for hdr in possible_options:
if hdr not in totals.keys():
totals[hdr] = summarytable[item, hdr]
else:
totals[hdr] += summarytable[item, hdr]
data.append(summarytable[item, hdr])
table.append([item] + data)
@ -1332,10 +1338,16 @@ def run_report(request, report):
for series in table:
series_names.append(series[0])
# Add total row to table
total_data = ['Total']
for hdr in possible_options:
total_data.append(str(totals[hdr]))
return render(request, 'helpdesk/report_output.html', {
'title': title,
'charttype': charttype,
'data': table,
'total_data': total_data,
'headings': column_headings,
'series_names': series_names,
'morrisjs_data': morrisjs_data,