Compare commits

..

No commits in common. "8597e53599dc666f5dce6a7bac6b9421ab19de09" and "9c50e5891fba4f329a9b739a4928ce8782ef8d58" have entirely different histories.

6 changed files with 17 additions and 58 deletions

View File

@ -1,13 +1,11 @@
import os
import datetime
from math import round, ceil
from math import floor
from django.db import models
from django.urls import reverse
from django.dispatch import receiver
from django.db.models.signals import post_delete, pre_save
from django.utils.translation import gettext as _
from django.utils import timezone
from django.conf import settings
from lostplaces.models.abstract_models import Submittable, Taggable, Mapable, Expireable
@ -94,6 +92,8 @@ class Place(Submittable, Taggable, Mapable):
return {'latitude': latitude, 'longitude': longitude}
def calculate_place_level(self):
self.remove_expired_votes()
if self.placevotings.count() == 0:
self.level = 5
self.save()
@ -104,19 +104,13 @@ class Place(Submittable, Taggable, Mapable):
for vote in self.placevotings.all():
level += vote.vote
self.level = round(level / self.placevotings.count())
self.level = floor(level / self.placevotings.count())
self.save()
def calculate_voting_accuracy(self):
place_age = timezone.now() - self.submitted_when;
accuaries = [];
def remove_expired_votes(self):
for vote in self.placevotings.all():
vote_age = timezone.now() - vote.created_when;
accuracy = 100 - (100 / (place_age / vote_age))
accuaries.append(accuracy)
return ceil(sum(accuaries) / len(accuaries))
if vote.is_expired:
vote.delete()
def __str__(self):
return self.name

View File

@ -28,7 +28,12 @@
</div>
<div class="LP-Voting__Expiration">
The accuracy of the voting is {{voting.accuracy}}%
<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>

View File

@ -23,15 +23,7 @@
{% block maincontent %}
<article class="LP-PlaceDetail">
<header class="LP-PlaceDetail__Header">
<h1 class="LP-Headline">
{{ place.name }}
{% include 'partials/icons/place_favorite.html' %}
{% include 'partials/icons/place_visited.html' %}
{% if user.is_superuser %}
<a class="LP-Link" href="{{'/admin/lostplaces/place/'|addstr:place.id }}" target="_blank"><span class="LP-Link__Text">{% translate 'view place in admin panel' %}</span></a>
{% endif %}
</h1>
<h1 class="LP-Headline">{{ place.name }} {% include 'partials/icons/place_favorite.html' %} {% include 'partials/icons/place_visited.html' %}</h1>
{% if place.get_hero_image %}
<div class="LP-PlaceDetail__Image">
{% include '../partials/image.html' with source_url=place.get_hero_image.filename.hero.url link_url="#image"|addstr:place.get_hero_index_in_queryset %}

View File

@ -14,7 +14,7 @@
</div>
<div class="LP-Form__Composition LP-Form__Composition--buttons">
{% include 'partials/form/submit.html' with referer=request.META.HTTP_REFERER %}
{% include 'partials/form/submit.html' with referrer=request.META.HTTP_REFERER %}
</div>
</fieldset>

View File

@ -124,31 +124,3 @@ class PlaceTestCase(ModelTestCase):
self.model.__name__
)
)
def test_level_calculation(self):
place = self.place
explorer = place.submitted_by
PlaceVoting.objects.create(
submitted_by=explorer,
place=place,
vote=5,
expires_when=timezone.now()+self.delta
)
PlaceVoting.objects.create(
submitted_by=explorer,
place=place,
vote=2,
expires_when=timezone.now()+self.delta
)
PlaceVoting.objects.create(
submitted_by=explorer,
place=place,
vote=4,
expires_when=timezone.now()+self.delta
)
self.assertEqual(
4,
place.calculate_place_level()
)

View File

@ -74,8 +74,7 @@ class PlaceDetailView(IsAuthenticatedMixin, IsEligibleToSeePlaceMixin, View):
},
'placevoting': {
'users_vote': PlaceVoting.objects.filter(place=place, submitted_by=explorer).first(),
'all_choices': reversed(PLACE_LEVELS),
'accuracy': place.calculate_voting_accuracy()
'all_choices': reversed(PLACE_LEVELS)
}
}
return render(request, 'place/place_detail.html', context)
@ -205,11 +204,8 @@ class PlaceVisitDeleteView(IsAuthenticatedMixin, View):
class PlaceVoteView(IsEligibleToSeePlaceMixin, View):
delta = timedelta(weeks=24)
def get_place(self):
return get_object_or_404(Place, pk=self.kwargs['place_id'])
def get(self, request, place_id, vote):
place = self.get_place()
place = get_object_or_404(Place, id=place_id)
explorer = request.user.explorer
voting = PlaceVoting.objects.filter(