From 256039c034665783fc4d3afd205897e4f4f3cdc5 Mon Sep 17 00:00:00 2001 From: Sebastien Renard Date: Tue, 19 Nov 2024 16:04:30 +0100 Subject: [PATCH] better handling zero-data conditions in graph --- billing/views.py | 2 +- leads/views.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/billing/views.py b/billing/views.py index 20b944b2..f68ba56b 100644 --- a/billing/views.py +++ b/billing/views.py @@ -742,7 +742,7 @@ def graph_yearly_billing(request): growth.append(None) last_turnover = current_turnover - if years[-1] == date.today().year: + if years and years[-1] == date.today().year: growth.pop() # Don't compute for on-going year. graph_data.append(["x"] + years) # X (years) axis diff --git a/leads/views.py b/leads/views.py index 4f168081..9a9adddc 100644 --- a/leads/views.py +++ b/leads/views.py @@ -511,6 +511,9 @@ def graph_leads_activity(request): if subsidiary: leads = leads.filter(subsidiary=subsidiary) + if not leads: + return HttpResponse('') + # lead creation rate per week first_lead_creation_date = leads.aggregate(Min("creation_date")).get("creation_date__min", datetime.now()).date() today = date.today()