[swatbot] [PATCH] swatapp/views: fix view when query is empty


Alexandre Belloni
 

When all the pending builds have been annotated, basequery is empty and
basequery[pageobj.start_index()-1:pageobj.end_index()] is failing with a
"Negative indexing is not supported" exception. Instead, exit early by
rendering the page with empty results.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
swatapp/views.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/swatapp/views.py b/swatapp/views.py
index 04048a5cbe7a..44be985d9512 100644
--- a/swatapp/views.py
+++ b/swatapp/views.py
@@ -48,6 +48,7 @@ def mainindex(request, indexfilter=None):
PERPAGE = 25

results = []
+ context = {}

if indexfilter == "swat":
failuresq = StepFailure.objects.filter(triage=TriageStatus.PENDING)
@@ -64,6 +65,11 @@ def mainindex(request, indexfilter=None):
dummyresults = list(range(0, itemnum))
paginator = Paginator(dummyresults, PERPAGE)
pageobj = paginator.get_page(page_number)
+ context['pageobj'] = pageobj
+
+ if itemnum == 0:
+ context['results'] = []
+ return render(request, 'swatapp/index.html', context)

# Only populate results for the entries we're going to display. Means
# we can't use paginator properly
@@ -98,9 +104,7 @@ def mainindex(request, indexfilter=None):
spancount += len(mainbuild_failures) + 1
results.append((collection, mainbuild, mainbuild_failures, subbuilds, spancount))

- context = {}
context['results'] = results
- context['pageobj'] = pageobj
return render(request, 'swatapp/index.html', context)

@login_required(login_url='/accounts/login/')
--
2.29.2

Join swat@lists.yoctoproject.org to automatically receive all group messages.