#58 Voting UI is bugged when no vote was submitted

This commit is contained in:
reverend 2021-12-31 15:56:31 +01:00
parent 1de203ad40
commit 78efe9bebb
4 changed files with 27 additions and 19 deletions

View File

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

View File

@ -6,7 +6,7 @@
Place level
</h2>
<div class="LP-Voting__Choices">
{% for choice in voting.get_all_choices %}
{% for choice in voting.all_choices %}
<a href="{% url 'place_vote' place_id=place.id vote=choice.0 %}" class="LP-Voting__Vote {% if choice.0 <= place.level %} LP-Voting__Vote--overall{% endif %}" title="Vote place as &quot;{{choice.1}}&quot;">
<i class="mdi mdi-shield-home"></i>
<span class="LP-Voting__Label">
@ -19,21 +19,23 @@
{{place.get_level_display}}
</div>
</div>
<div class="LP-Voting__Right">
<div class="LP-Voting__Info">
<div class="LP-Voting__UserVote">
<span class="LP-Voting__InfoLabel">You voted this place as</span>
<span class="LP-Voting__Vote">{{voting.get_human_readable_level}} / {{voting.vote}}</span>
</div>
{% if voting.users_vote %}
<div class="LP-Voting__Right">
<div class="LP-Voting__Info">
<div class="LP-Voting__UserVote">
<span class="LP-Voting__InfoLabel">You voted this place as</span>
<span class="LP-Voting__Vote">{{voting.users_vote.get_human_readable_level}} <i>Level {{voting.users_vote.vote}}</i></span>
</div>
<div class="LP-Voting__Expiration">
<span class="LP-Voting__InfoLabel">Your vote expires on</span>
<span class="LP-Voting__Date">
<time datetime="{{voting.expires_when|date:'Y-m-d'}}">
{{voting.expires_when|date:'d.m.Y'}}
</time>
</span>
<div class="LP-Voting__Expiration">
<span class="LP-Voting__InfoLabel">Your vote expires on</span>
<span class="LP-Voting__Date">
<time datetime="{{voting.expires_when|date:'Y-m-d'}}">
{{voting.users_vote.expires_when|date:'d.m.Y'}}
</time>
</span>
</div>
</div>
</div>
</div>
{% endif %}
</div>

View File

@ -14,7 +14,6 @@ from lostplaces.tests.views import (
)
class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
@classmethod
def setUpTestData(cls):
user = User.objects.create_user(

View File

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