modified top-list api, junior-list api and junior-points api, nodified rank method, added mail for deactivating user from admin

This commit is contained in:
abutalib-kiwi
2023-08-24 19:34:59 +05:30
parent 1a2fd2d3a8
commit 2e0ceb8c92
11 changed files with 94 additions and 71 deletions

View File

@ -5,7 +5,8 @@ from django.conf import settings
from templated_email import send_templated_mail
from .models import JuniorPoints
from base.constants import NUMBER
from django.db.models import F
from django.db.models import F, Window
from django.db.models.functions.window import Rank
# junior notification
# email for sending email
# when guardian create junior profile
@ -61,3 +62,19 @@ def update_positions_based_on_points():
junior_point.position = position
junior_point.save()
position += NUMBER['one']
def get_junior_leaderboard_rank(junior_obj):
"""
to get junior's position/rank
:param junior_obj:
:return: junior's position/rank
"""
queryset = JuniorPoints.objects.prefetch_related('junior', 'junior__auth').annotate(rank=Window(
expression=Rank(),
order_by=[F('total_points').desc(), 'junior__created_at']
)).order_by('-total_points', 'junior__created_at')
junior = next((query for query in queryset if query.junior == junior_obj), None)
return junior.rank if junior else None