#58 Voting UI is bugged when no vote was submitted
This commit is contained in:
parent
1de203ad40
commit
78efe9bebb
@ -94,7 +94,9 @@ class Place(Submittable, Taggable, Mapable):
|
|||||||
self.remove_expired_votes()
|
self.remove_expired_votes()
|
||||||
|
|
||||||
if self.placevotings.count() == 0:
|
if self.placevotings.count() == 0:
|
||||||
return 5
|
self.level = 5
|
||||||
|
self.save()
|
||||||
|
return
|
||||||
|
|
||||||
level = 0
|
level = 0
|
||||||
|
|
||||||
@ -102,6 +104,7 @@ class Place(Submittable, Taggable, Mapable):
|
|||||||
level += vote.vote
|
level += vote.vote
|
||||||
|
|
||||||
self.level = floor(level / self.placevotings.count())
|
self.level = floor(level / self.placevotings.count())
|
||||||
|
self.save()
|
||||||
|
|
||||||
def remove_expired_votes(self):
|
def remove_expired_votes(self):
|
||||||
for vote in self.placevotings.all():
|
for vote in self.placevotings.all():
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
Place level
|
Place level
|
||||||
</h2>
|
</h2>
|
||||||
<div class="LP-Voting__Choices">
|
<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 "{{choice.1}}"">
|
<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 "{{choice.1}}"">
|
||||||
<i class="mdi mdi-shield-home"></i>
|
<i class="mdi mdi-shield-home"></i>
|
||||||
<span class="LP-Voting__Label">
|
<span class="LP-Voting__Label">
|
||||||
@ -19,21 +19,23 @@
|
|||||||
{{place.get_level_display}}
|
{{place.get_level_display}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="LP-Voting__Right">
|
{% if voting.users_vote %}
|
||||||
<div class="LP-Voting__Info">
|
<div class="LP-Voting__Right">
|
||||||
<div class="LP-Voting__UserVote">
|
<div class="LP-Voting__Info">
|
||||||
<span class="LP-Voting__InfoLabel">You voted this place as</span>
|
<div class="LP-Voting__UserVote">
|
||||||
<span class="LP-Voting__Vote">{{voting.get_human_readable_level}} / {{voting.vote}}</span>
|
<span class="LP-Voting__InfoLabel">You voted this place as</span>
|
||||||
</div>
|
<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">
|
<div class="LP-Voting__Expiration">
|
||||||
<span class="LP-Voting__InfoLabel">Your vote expires on</span>
|
<span class="LP-Voting__InfoLabel">Your vote expires on</span>
|
||||||
<span class="LP-Voting__Date">
|
<span class="LP-Voting__Date">
|
||||||
<time datetime="{{voting.expires_when|date:'Y-m-d'}}">
|
<time datetime="{{voting.expires_when|date:'Y-m-d'}}">
|
||||||
{{voting.expires_when|date:'d.m.Y'}}
|
{{voting.users_vote.expires_when|date:'d.m.Y'}}
|
||||||
</time>
|
</time>
|
||||||
</span>
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
</div>
|
</div>
|
@ -14,7 +14,6 @@ from lostplaces.tests.views import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
class TestHomeView(GlobalTemplateTestCaseMixin, ViewTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
user = User.objects.create_user(
|
user = User.objects.create_user(
|
||||||
|
@ -19,7 +19,8 @@ from django.urls import reverse_lazy, reverse
|
|||||||
from lostplaces.models import (
|
from lostplaces.models import (
|
||||||
Place,
|
Place,
|
||||||
PlaceImage,
|
PlaceImage,
|
||||||
PlaceVoting
|
PlaceVoting,
|
||||||
|
PLACE_LEVELS
|
||||||
)
|
)
|
||||||
|
|
||||||
from lostplaces.views.base_views import (
|
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}),
|
'submit_url': reverse('place_tag_submit', kwargs={'tagged_id': place.id}),
|
||||||
'delete_url_name': 'place_tag_delete'
|
'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)
|
return render(request, 'place/place_detail.html', context)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user