Skip to content

Commit

Permalink
Règle un problème d'affichage des votes dans les MPs
Browse files Browse the repository at this point in the history
  • Loading branch information
Migwel committed Aug 12, 2022
1 parent 5ea18c2 commit d0d1427
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 1 addition & 5 deletions zds/mp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,7 @@ def set_user_vote(self, user, vote):
def get_votes(self):
"""Get the non-anonymous votes"""
if not hasattr(self, "votes"):
self.votes = (
PrivatePostVote.objects.filter(private_post=self)
.select_related("user")
.all()
)
self.votes = PrivatePostVote.objects.filter(private_post=self).select_related("user").all()

return self.votes

Expand Down
6 changes: 5 additions & 1 deletion zds/mp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from zds.mp.utils import send_mp, send_message_mp
from zds.utils.paginator import ZdSPagingListView
from .forms import PrivateTopicForm, PrivatePostForm, PrivateTopicEditForm
from .models import PrivateTopic, PrivateTopicRead, PrivatePost, mark_read, NotReachableError
from .models import PrivateTopic, PrivateTopicRead, PrivatePost, mark_read, NotReachableError, PrivatePostVote


class PrivateTopicList(ZdSPagingListView):
Expand Down Expand Up @@ -255,6 +255,10 @@ def get_context_data(self, **kwargs):
else:
context["user_can_modify"] = []

votes = PrivatePostVote.objects.filter(user_id=self.request.user.pk, private_post__in=context["posts"]).all()
context["user_like"] = [vote.private_post_id for vote in votes if vote.positive]
context["user_dislike"] = [vote.private_post_id for vote in votes if not vote.positive]

return context

def get_queryset(self):
Expand Down

0 comments on commit d0d1427

Please sign in to comment.