diff --git a/shynet/dashboard/templatetags/helpers.py b/shynet/dashboard/templatetags/helpers.py index 88b6d74..ae1bf2d 100644 --- a/shynet/dashboard/templatetags/helpers.py +++ b/shynet/dashboard/templatetags/helpers.py @@ -61,25 +61,28 @@ def relative_stat_tone( @register.simple_tag def percent_change_display(start, end): - if start == None or end == None: - return SafeString("Δ n/a") - if start == end: - direction = "Δ " - else: - direction = "↑ " if end > start else "↓ " - - if start == 0 and end != 0: - pct_change = "100%" - elif start == 0: - pct_change = "0%" - else: - change = int(round(100 * abs(end - start) / max(start, 1))) - if change > 999: - return "> 999%" + try: + if start == None or end == None: + return SafeString("Δ n/a") + if start == end: + direction = "Δ " else: - pct_change = str(change) + "%" + direction = "↑ " if end > start else "↓ " - return SafeString(direction + pct_change) + if start == 0 and end != 0: + pct_change = "100%" + elif start == 0: + pct_change = "0%" + else: + change = int(round(100 * abs(end - start) / max(start, 1))) + if change > 999: + return "> 999%" + else: + pct_change = str(change) + "%" + + return SafeString(direction + pct_change) + except: # TODO: filter for specific issues + return SafeString("Δ ?") @register.inclusion_tag("dashboard/includes/sidebar_footer.html")