From 3c7b41aace53bf9d96f88fa64a94bf0b48392317 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 8 Feb 2017 11:16:11 +0000 Subject: [PATCH] Limit months shown to current and past MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Matches what we do on the usage page. No need to see months in the future because there’s no way you’ll have sent any messages in those months, unless you’re Marty McFly. --- app/main/views/dashboard.py | 7 +++- app/templates/views/dashboard/monthly.html | 44 +++++++++++----------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 230ff3c96..8de2ee003 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -215,12 +215,17 @@ def format_monthly_stats_to_list(historical_stats): return sorted(( dict( date=key, - name=datetime(int(key[0:4]), int(key[5:7]), 1).strftime('%B'), + future=YYYY_MM_to_datetime(key) > datetime.utcnow(), + name=YYYY_MM_to_datetime(key).strftime('%B'), **aggregate_status_types(value) ) for key, value in historical_stats.items() ), key=lambda x: x['date']) +def YYYY_MM_to_datetime(string): + return datetime(int(string[0:4]), int(string[5:7]), 1) + + def aggregate_status_types(counts_dict): return get_dashboard_totals({ '{}_counts'.format(message_type): { diff --git a/app/templates/views/dashboard/monthly.html b/app/templates/views/dashboard/monthly.html index 6b5d88d25..dd4e13fbc 100644 --- a/app/templates/views/dashboard/monthly.html +++ b/app/templates/views/dashboard/monthly.html @@ -36,28 +36,30 @@ ], field_headings_visible=False ) %} - {% call row_heading() %} - {{ month.name }} - {% endcall %} - {% for counts, template_type in [ - (month.email_counts, 'email'), - (month.sms_counts, 'sms') - ] %} - {% call field(align='left') %} - {{ big_number( - counts.requested, - message_count_label(counts.requested, template_type, suffix=''), - smallest=True, - ) }} - {% if counts.requested %} - - {{ counts.failed }} failed - - {% else %} - – - {% endif %} + {% if not month.future %} + {% call row_heading() %} + {{ month.name }} {% endcall %} - {% endfor %} + {% for counts, template_type in [ + (month.email_counts, 'email'), + (month.sms_counts, 'sms') + ] %} + {% call field(align='left') %} + {{ big_number( + counts.requested, + message_count_label(counts.requested, template_type, suffix=''), + smallest=True, + ) }} + {% if counts.requested %} + + {{ counts.failed }} failed + + {% else %} + – + {% endif %} + {% endcall %} + {% endfor %} + {% endif %} {% endcall %} {% endif %}