Skip to content

Commit

Permalink
url shortner ordering issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
adnankattekaden committed Dec 13, 2023
1 parent 1593921 commit 9a9e244
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
42 changes: 19 additions & 23 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import uuid

from decouple import config as decouple_config
from django.core.files.storage import FileSystemStorage
from django.db import transaction
from django.db.models import F, Sum, Q
from rest_framework import serializers
Expand Down Expand Up @@ -130,7 +129,7 @@ def get_rank(self, obj):
Wallet.objects.filter(karma__gte=user_karma)
.exclude(
Q(user__user_role_link_user__role__title__in=[
RoleType.ENABLER.value, RoleType.MENTOR.value])
RoleType.ENABLER.value, RoleType.MENTOR.value])
).order_by('-karma')
)

Expand All @@ -154,14 +153,14 @@ def get_interest_groups(self, obj):
if KarmaActivityLog.objects.filter(
task__ig=ig_link.ig, user=obj, appraiser_approved=True
)
.aggregate(Sum("karma"))
.get("karma__sum")
is None
.aggregate(Sum("karma"))
.get("karma__sum")
is None
else KarmaActivityLog.objects.filter(
task__ig=ig_link.ig, user=obj, appraiser_approved=True
)
.aggregate(Sum("karma"))
.get("karma__sum")
.aggregate(Sum("karma"))
.get("karma__sum")
)
interest_groups.append(
{"id": ig_link.ig.id, "name": ig_link.ig.name, "karma": total_ig_karma}
Expand Down Expand Up @@ -219,35 +218,32 @@ def get_role(self, obj):
return ["Learner"] if len(roles) == 0 else roles

def get_rank(self, obj):
roles = self.context.get("roles")
roles = self.get_roles(obj)
user_karma = obj.wallet_user.karma
if RoleType.MENTOR.value in roles:
ranks = Wallet.objects.filter(
user__user_role_link_user__verified=True,
user__user_role_link_user__role__title=RoleType.MENTOR.value,
karma__gte=user_karma,
).count()
).order_by('-karma', '-updated_at', 'created_at')
elif RoleType.ENABLER.value in roles:
ranks = Wallet.objects.filter(
user__user_role_link_user__verified=True,
user__user_role_link_user__role__title=RoleType.ENABLER.value,
karma__gte=user_karma,
).count()
).order_by('-karma', '-updated_at', 'created_at')
else:
ranks = (
Wallet.objects.filter(
karma__gte=user_karma, user__user_role_link_user__verified=True)
Wallet.objects.filter(karma__gte=user_karma)
.exclude(
Q(
user__user_role_link_user__role__title__in=[
RoleType.ENABLER.value,
RoleType.MENTOR.value,
]
)
)
.count()
Q(user__user_role_link_user__role__title__in=[
RoleType.ENABLER.value, RoleType.MENTOR.value])
).order_by('-karma')
)
return ranks if ranks > 0 else None

for count, _rank in enumerate(ranks, start=1):
if obj == _rank.user:
return count

def get_karma(self, obj):
return total_karma.karma if (total_karma := obj.wallet_user) else None
Expand Down Expand Up @@ -402,7 +398,7 @@ def create_karma_activity_log(task_title, karma_value):
dl = WebHookActions.SEPARATOR.value
discord_id = User.objects.get(id=user_id).discord_id
value = f"{task.hashtag}{dl}{karma_value}{dl}{discord_id}{dl}{karma_log.id}"

DiscordWebhooks.general_updates(
WebHookCategory.KARMA_INFO.value,
WebHookActions.UPDATE.value,
Expand All @@ -411,7 +407,7 @@ def create_karma_activity_log(task_title, karma_value):
else:
KarmaActivityLog.objects.filter(
task_id=task.id, user_id=user_id
).delete()
).first().delete()
Wallet.objects.filter(user_id=user_id).update(
karma=F("karma") + karma_value,
updated_by_id=user_id
Expand Down
2 changes: 1 addition & 1 deletion api/url_shortener/url_shortener_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def post(self, request):
[RoleType.ADMIN.value, RoleType.FELLOW.value, RoleType.ASSOCIATE.value]
)
def get(self, request):
url_shortener_objects = UrlShortener.objects.all()
url_shortener_objects = UrlShortener.objects.all().order_by('-created_at')

paginated_queryset = CommonUtils.get_paginated_queryset(
url_shortener_objects,
Expand Down

0 comments on commit 9a9e244

Please sign in to comment.