diff --git a/ennstatus/donate/views.py b/ennstatus/donate/views.py --- a/ennstatus/donate/views.py +++ b/ennstatus/donate/views.py @@ -60,7 +60,7 @@ def received(): current_app.logger.warn('No donations found!') return render_template('donate/received.html', form=form, csv_file=None, - year=None, month=None) + year=None, month=None, total=None) if request.method == 'POST': current_app.logger.debug('Validating form') @@ -82,7 +82,7 @@ def received(): current_app.logger.warn('Date %s not found' % filename) return render_template('donate/received.html', form=form, csv_file=None, - year=year, month=month) + year=year, month=month, total=None) else: filename = files[-1] current_app.logger.info('Showing last date %s' % filename) @@ -91,7 +91,10 @@ def received(): form.month.data = '{:02d}'.format(int(month)) csv_file = load_csv(filename) + total = str(sum(int(row[2]) for row in csv_file)) + csv_file = load_csv(filename) + current_app.logger.info('Return result') return render_template('donate/received.html', form=form, csv_file=csv_file, - year=year, month=month) + year=year, month=month, total=total) diff --git a/ennstatus/templates/donate/macros.html b/ennstatus/templates/donate/macros.html --- a/ennstatus/templates/donate/macros.html +++ b/ennstatus/templates/donate/macros.html @@ -10,7 +10,7 @@ {{ number }} {% endmacro %} -{% macro create_donations_table(csv_file) %} +{% macro create_donations_table(csv_file, total) %}
@@ -30,6 +30,10 @@ {% endfor %} + + + +
{{ colorize_numbers(row[2]) }}
Total:{{ colorize_numbers(total) }}
diff --git a/ennstatus/templates/donate/received.html b/ennstatus/templates/donate/received.html --- a/ennstatus/templates/donate/received.html +++ b/ennstatus/templates/donate/received.html @@ -30,7 +30,7 @@
{% if csv_file %} - {{ macros.create_donations_table(csv_file) }} + {{ macros.create_donations_table(csv_file, total) }} {% else %} {% if year and month %}

No donations found for {{ '-'.join([year, month]) }}!