Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Forum] Display who upvoted/downvoted each post. Closes #346 #423

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Display reactions using bootstrap tooltip
  • Loading branch information
stopnoanime committed Nov 13, 2024
commit 6a5e7b58032006b7d8a883c0190488812df58dd4
8 changes: 1 addition & 7 deletions oioioi/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,7 @@ def is_reporter_banned(self):
return False

return Ban.is_banned(self.thread.category.forum, self.reported_by)

def get_upvotes(self):
return self.reactions.filter(type_of_reaction='UPVOTE')

def get_downvotes(self):
return self.reactions.filter(type_of_reaction='DOWNVOTE')



post_reaction_types = EnumRegistry(
entries=[
Expand Down
8 changes: 0 additions & 8 deletions oioioi/forum/static/common/forum.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,4 @@
.anchor-jump-fix {
margin-top: -$oioioi-navbar-height;
margin-bottom: $oioioi-navbar-height;
}

.reaction-list {
display: none;
}

.reaction-symbol:hover + .reaction-list {
display: inline;
}
15 changes: 10 additions & 5 deletions oioioi/forum/templates/forum/thread-element-footer.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load i18n %}
{% load check_perm %}
{% load get_user_name %}
{% load format_reactions %}

{% url 'forum_post_edit' contest_id=contest.id category_id=category.id thread_id=thread.id post_id=post.id as forum_post_edit_url %}
{% url 'forum_post_delete' contest_id=contest.id category_id=category.id thread_id=thread.id post_id=post.id as forum_post_delete_url %}
Expand All @@ -18,11 +19,13 @@
<a href="#" data-post-url="{{ forum_post_toggle_reaction_url }}?reaction=upvote">
{% endif %}

<span class="{% if post.user_upvoted %} text-success {% else %} text-muted {% endif %} reaction-symbol">
<span
class="{% if post.user_upvoted %} text-success {% else %} text-muted {% endif %}"
data-toggle="tooltip" title="{% format_reactions post "UPVOTE" %}"
>
<i class="fa-solid fa-plus"></i> {{ post.upvotes_count }}
</span>
{% include "forum/thread-post-reactions.html" with reactions=post.get_upvotes %}


{% if can_interact_with_users %}
</a>
{% endif %}
Expand All @@ -31,10 +34,12 @@
<a href="#" data-post-url="{{ forum_post_toggle_reaction_url }}?reaction=downvote">
{% endif %}

<span class="{% if post.user_downvoted %} text-danger {% else %} text-muted {% endif %} reaction-symbol">
<span
class="{% if post.user_downvoted %} text-danger {% else %} text-muted {% endif %}"
data-toggle="tooltip" title="{% format_reactions post "DOWNVOTE" %}"
>
<i class="fa-solid fa-minus"></i> {{ post.downvotes_count }}
</span>
{% include "forum/thread-post-reactions.html" with reactions=post.get_downvotes %}

{% if can_interact_with_users %}
</a>
Expand Down
8 changes: 0 additions & 8 deletions oioioi/forum/templates/forum/thread-post-reactions.html

This file was deleted.

Empty file.
18 changes: 18 additions & 0 deletions oioioi/forum/templatetags/format_reactions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django import template
from django.utils.translation import gettext as _
from oioioi.base.utils import get_user_display_name

register = template.Library()

@register.simple_tag
def format_reactions(post, rtype):
output = ', '.join([
get_user_display_name(reaction.author)
for reaction in
post.reactions.filter(type_of_reaction=rtype).select_related('author')[:10]
])

if(post.reactions.filter(type_of_reaction=rtype).count() > 10):
output += _(' and others')

return output