Hide navigation bar items

If there are no games/purchases/sessions,
hide the related navbar items
This commit is contained in:
Lukáš Kucharczyk 2023-01-04 17:19:40 +01:00
parent 84c92fe654
commit 5c50e059e6
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
4 changed files with 16 additions and 2 deletions

2
CHANGELOG.md Normal file
View File

@ -0,0 +1,2 @@
## Unreleased
* Hide navigation bar items if there are no games/purchases/sessions

View File

@ -23,9 +23,15 @@
<ul
class="flex flex-col md:flex-row p-4 mt-4 dark:text-white">
<li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'add_game' %}">New Game</a></li>
{% if game_available and platform_available %}
<li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'add_purchase' %}">New Purchase</a></li>
{% endif %}
{% if purchase_available %}
<li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'add_session' %}">New Session</a></li>
{% endif %}
{% if session_count > 0 %}
<li><a class="block py-2 pl-3 pr-4 hover:underline" href="{% url 'list_sessions' %}">All Sessions</a></li>
{% endif %}
</ul>
</div>
</div>

View File

@ -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):

View File

@ -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",
],
},
},