From 78efe9bebb68a183bd6f6f392a12cf63d1ccb748 Mon Sep 17 00:00:00 2001 From: reverend Date: Fri, 31 Dec 2021 15:56:31 +0100 Subject: [PATCH] #58 Voting UI is bugged when no vote was submitted --- django_lostplaces/lostplaces/models/place.py | 5 ++- .../lostplaces/templates/partials/voting.html | 32 ++++++++++--------- .../lostplaces/tests/views/test_views.py | 1 - .../lostplaces/views/place_views.py | 8 +++-- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/django_lostplaces/lostplaces/models/place.py b/django_lostplaces/lostplaces/models/place.py index 2df13b4..9ec4c99 100644 --- a/django_lostplaces/lostplaces/models/place.py +++ b/django_lostplaces/lostplaces/models/place.py @@ -94,7 +94,9 @@ class Place(Submittable, Taggable, Mapable): self.remove_expired_votes() if self.placevotings.count() == 0: - return 5 + self.level = 5 + self.save() + return level = 0 @@ -102,6 +104,7 @@ class Place(Submittable, Taggable, Mapable): level += vote.vote self.level = floor(level / self.placevotings.count()) + self.save() def remove_expired_votes(self): for vote in self.placevotings.all(): diff --git a/django_lostplaces/lostplaces/templates/partials/voting.html b/django_lostplaces/lostplaces/templates/partials/voting.html index 0b7ebcf..169b8ca 100644 --- a/django_lostplaces/lostplaces/templates/partials/voting.html +++ b/django_lostplaces/lostplaces/templates/partials/voting.html @@ -6,7 +6,7 @@ Place level
- {% for choice in voting.get_all_choices %} + {% for choice in voting.all_choices %} @@ -19,21 +19,23 @@ {{place.get_level_display}}
-
-
-
- You voted this place as - {{voting.get_human_readable_level}} / {{voting.vote}} -
+ {% if voting.users_vote %} +
+
+
+ You voted this place as + {{voting.users_vote.get_human_readable_level}} Level {{voting.users_vote.vote}} +
-
- Your vote expires on - - - +
+ Your vote expires on + + + +
-
+ {% endif %}
\ No newline at end of file diff --git a/django_lostplaces/lostplaces/tests/views/test_views.py b/django_lostplaces/lostplaces/tests/views/test_views.py index c6f9b5d..d9f6c4c 100644 --- a/django_lostplaces/lostplaces/tests/views/test_views.py +++ b/django_lostplaces/lostplaces/tests/views/test_views.py @@ -14,7 +14,6 @@ from lostplaces.tests.views import ( ) class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase): - @classmethod def setUpTestData(cls): user = User.objects.create_user( diff --git a/django_lostplaces/lostplaces/views/place_views.py b/django_lostplaces/lostplaces/views/place_views.py index 71e08cb..f493ce5 100644 --- a/django_lostplaces/lostplaces/views/place_views.py +++ b/django_lostplaces/lostplaces/views/place_views.py @@ -19,7 +19,8 @@ from django.urls import reverse_lazy, reverse from lostplaces.models import ( Place, PlaceImage, - PlaceVoting + PlaceVoting, + PLACE_LEVELS ) from lostplaces.views.base_views import ( @@ -71,7 +72,10 @@ class PlaceDetailView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View): 'submit_url': reverse('place_tag_submit', kwargs={'tagged_id': place.id}), 'delete_url_name': 'place_tag_delete' }, - 'placevoting': PlaceVoting.objects.filter(place=place, submitted_by=explorer).first() + 'placevoting': { + 'users_vote': PlaceVoting.objects.filter(place=place, submitted_by=explorer).first(), + 'all_choices': reversed(PLACE_LEVELS) + } } return render(request, 'place/place_detail.html', context)