Skip to content

Commit

Permalink
fix: hotfix sort by likes (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
MagneticNeedle authored Oct 11, 2022
2 parents d79dd06 + 8ee32bf commit 603901c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions bfportal/bfportal/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@

<a class="hidden md:flex flex-row gap-x-1 items-center" href="https://www.patreon.com/battlefield_portal_community" target="_blank">
Support us on
<span class="text-bf2042-4 font-bold hover:text-bf2042-6 transition duration-200 ease-in-out">
<span class="text-bf2042-4 hover:text-bf2042-6 transition duration-200 ease-in-out">
<img src="{% static 'svgs/patreon.svg' %}" alt="" onmouseenter="handle_hover_for_footer_heart(this)" width="{{ icon_width }}">
</span>
</a>


<a class="hidden md:flex flex-row gap-x-1 items-center" href="https://twitter.com/BF2042_Portal/" target="_blank">
Follow us on
<span class="text-bf2042-4 font-bold hover:text-bf2042-6 transition duration-200 ease-in-out">
<span class="text-bf2042-4 hover:text-bf2042-6 transition duration-200 ease-in-out">
<img src="{% static 'svgs/twitter.svg' %}" alt="" onmouseenter="handle_hover_for_footer_heart(this)" width="{{ icon_width }}">
</span>
</a>

<a class="hidden md:flex flex-row gap-x-1 items-center" href="https://github.com/battlefield-portal-community" target="_blank">
Codebase at
<span class="text-bf2042-4 font-bold hover:text-bf2042-6 transition duration-200 ease-in-out">
<span class="text-bf2042-4 hover:text-bf2042-6 transition duration-200 ease-in-out">
<img src="{% static 'svgs/gh.svg' %}" alt="" onmouseenter="handle_hover_for_footer_heart(this)" width="{{ icon_width }}">
</span>
</a>
Expand Down
6 changes: 4 additions & 2 deletions bfportal/core/models/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from core.utils.helper import safe_cast
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.db import models
from django.db.models import Q
from django.db.models import Count, Q
from django.db.models import Value as V
from django.db.models.functions import Concat
from django.http import HttpRequest
Expand Down Expand Up @@ -81,7 +81,9 @@ def apply_filters(request: HttpRequest, posts: models.query.QuerySet):
if sort := request.GET.get("sort", None):
match sort:
case "like":
all_posts = all_posts.order_by("-likes")
all_posts = all_posts.annotate(likes=Count("liked_by")).order_by(
"-likes"
)
case "latest":
pass

Expand Down
4 changes: 2 additions & 2 deletions bfportal/core/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.contrib.auth.models import Group, User
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.db.models import Q
from django.db.models import Count, Q
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.http import HttpRequest, HttpResponse
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_context(self, request, *args, **kwargs): # noqa: D102
context["requested_user"] = user_acc
context["latest_post"] = all_posts.first()
context["total_num_posts"] = len(all_posts)
context["earned_likes"] = all_posts.aggregate(models.Sum("likes"))["likes__sum"]
context["earned_likes"] = sum(all_posts.aggregate(Count("liked_by")).values())
context["owners"] = os.getenv("OWNERS", "").split(",")
return context

Expand Down

0 comments on commit 603901c

Please sign in to comment.