From 5c50e059e662146bbbe2b82ac914186414297ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Wed, 4 Jan 2023 17:19:40 +0100 Subject: [PATCH] Hide navigation bar items If there are no games/purchases/sessions, hide the related navbar items --- CHANGELOG.md | 2 ++ src/web/tracker/templates/base.html | 6 ++++++ src/web/tracker/views.py | 9 +++++++-- src/web/web/settings.py | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..81d6b66 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,2 @@ +## Unreleased +* Hide navigation bar items if there are no games/purchases/sessions diff --git a/src/web/tracker/templates/base.html b/src/web/tracker/templates/base.html index 54a855e..31109ca 100644 --- a/src/web/tracker/templates/base.html +++ b/src/web/tracker/templates/base.html @@ -23,9 +23,15 @@ diff --git a/src/web/tracker/views.py b/src/web/tracker/views.py index 3a27817..66130cb 100644 --- a/src/web/tracker/views.py +++ b/src/web/tracker/views.py @@ -3,8 +3,13 @@ from django.shortcuts import render from .models import Game, Platform, Purchase, Session from .forms import SessionForm, PurchaseForm, GameForm from datetime import datetime -from django.db.models import ExpressionWrapper, F, DurationField -import logging +def model_counts(request): + return { + "game_available": Game.objects.count() != 0, + "platform_available": Platform.objects.count() != 0, + "purchase_available": Purchase.objects.count() != 0, + "session_count": Session.objects.count(), + } def add_session(request): diff --git a/src/web/web/settings.py b/src/web/web/settings.py index de91566..e5f7e47 100644 --- a/src/web/web/settings.py +++ b/src/web/web/settings.py @@ -65,6 +65,7 @@ TEMPLATES = [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "tracker.views.model_counts", ], }, },