From ac73e8544697a63370b4728188d59df809faf197 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 2 Feb 2022 11:33:48 +0800 Subject: Umbrella count on admin page is done in core, not Jinja --- jimbrella/admin.py | 12 ++++++------ jimbrella/templates/admin/index.html | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'jimbrella') diff --git a/jimbrella/admin.py b/jimbrella/admin.py index 4454c69..8a52bb8 100644 --- a/jimbrella/admin.py +++ b/jimbrella/admin.py @@ -29,16 +29,16 @@ def check_privilege(): def index(): umbrellas = db.read() # count # of umbrellas in each status - statuses = { + status_count = { status: len([u for u in umbrellas if u["status"] == status]) for status in ("available", "lent", "overdue") } return render_template( "admin/index.html", - umbrellas=umbrellas, - available=statuses["available"], - lent=statuses["lent"], - overdue=statuses["overdue"], + umbrellas=len(umbrellas), + available=status_count["available"], + lent=status_count["lent"], + overdue=status_count["overdue"], mobile=user_agent(request.user_agent.string).is_mobile, ) @@ -56,7 +56,7 @@ def umbrellas(): return render_template( template, umbrellas=umbrellas, - edit=int(edit) if edit.isnumeric() else None, + edit=int(edit) if edit is not None and edit.isnumeric() else None, error=error, ) diff --git a/jimbrella/templates/admin/index.html b/jimbrella/templates/admin/index.html index 940f2c2..73ae5f6 100644 --- a/jimbrella/templates/admin/index.html +++ b/jimbrella/templates/admin/index.html @@ -15,7 +15,7 @@