From 5c1ced63b097a54543d746e46a294c9f7604972c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20J=C3=BClg?= <tobias.juelg@tum.de> Date: Sat, 7 May 2022 15:08:10 +0200 Subject: [PATCH] Fix existing elections view The fronted now correctly shows when no elections exist in both management and voter frontend --- management/views.py | 2 +- vote/templates/vote/index.html | 6 +++++- vote/templates/vote/spectator.html | 6 +++++- vote/views.py | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/management/views.py b/management/views.py index 489e81e..7cf1c07 100644 --- a/management/views.py +++ b/management/views.py @@ -93,7 +93,7 @@ def session_detail(request, pk=None): session = manager.sessions.get(id=pk) context = { 'session': session, - 'existing_elections': bool(session.elections), + 'existing_elections': (session.elections.count() > 0), 'open_elections': open_elections(session), 'upcoming_elections': upcoming_elections(session), 'published_elections': published_elections(session), diff --git a/vote/templates/vote/index.html b/vote/templates/vote/index.html index 08ec37e..2435d84 100644 --- a/vote/templates/vote/index.html +++ b/vote/templates/vote/index.html @@ -14,7 +14,11 @@ </div> </div> <div id="electionCard"> - {% if open_elections %} + {% if not existing_elections %} + <div class="list-group-item mt-3"> + <span>There are no elections for this session</span> + </div> + {% elif open_elections %} <div class="card shadow mb-2"> <div class="card-header"> <h4>Open Elections</h4> diff --git a/vote/templates/vote/spectator.html b/vote/templates/vote/spectator.html index a77fc3d..79c2085 100644 --- a/vote/templates/vote/spectator.html +++ b/vote/templates/vote/spectator.html @@ -15,7 +15,11 @@ </div> </div> <div id="electionCard"> - {% if open_elections %} + {% if not existing_elections %} + <div class="list-group-item mt-3"> + <span>There are no elections for this session</span> + </div> + {% elif open_elections %} <div class="card shadow mb-2"> <div class="card-header"> <h4>Open Elections</h4> diff --git a/vote/views.py b/vote/views.py index 315d9b9..d5774cb 100644 --- a/vote/views.py +++ b/vote/views.py @@ -71,6 +71,7 @@ def index(request): 'title': session.title, 'meeting_link': session.meeting_link, 'voter': voter, + 'existing_elections': (session.elections.count() > 0), 'open_elections': list_elections(open_elections(session)), 'upcoming_elections': list_elections(upcoming_elections(session)), 'published_elections': list_elections(published_elections(session)), @@ -172,6 +173,7 @@ def spectator(request, uuid): context = { 'title': session.title, 'meeting_link': session.meeting_link, + 'existing_elections': (session.elections.count() > 0), 'open_elections': open_elections(session), 'upcoming_elections': upcoming_elections(session), 'published_elections': published_elections(session), -- GitLab