mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 10:05:21 +00:00
added notification for existing junior add, modified leaderboard method at every places
This commit is contained in:
@ -68,10 +68,14 @@ def notify_top_junior():
|
|||||||
task to send notification for top leaderboard junior to all junior's
|
task to send notification for top leaderboard junior to all junior's
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
junior_points_qs = JuniorPoints.objects.select_related('junior', 'junior__auth').annotate(rank=Window(
|
junior_points_qs = JuniorPoints.objects.filter(
|
||||||
|
junior__is_verified=True
|
||||||
|
).select_related(
|
||||||
|
'junior', 'junior__auth'
|
||||||
|
).annotate(rank=Window(
|
||||||
expression=Rank(),
|
expression=Rank(),
|
||||||
order_by=[F('total_points').desc(), 'junior__created_at']
|
order_by=[F('total_points').desc(), 'junior__created_at'])
|
||||||
)).order_by('-total_points', 'junior__created_at')
|
).order_by('-total_points', 'junior__created_at')
|
||||||
|
|
||||||
prev_top_position = junior_points_qs.filter(position=1).first()
|
prev_top_position = junior_points_qs.filter(position=1).first()
|
||||||
new_top_position = junior_points_qs.filter(rank=1).first()
|
new_top_position = junior_points_qs.filter(rank=1).first()
|
||||||
|
@ -259,10 +259,14 @@ class TopJuniorListAPIView(viewsets.ModelViewSet):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = JuniorPoints.objects.select_related('junior', 'junior__auth').annotate(rank=Window(
|
queryset = JuniorPoints.objects.filter(
|
||||||
|
junior__is_verified=True
|
||||||
|
).select_related(
|
||||||
|
'junior', 'junior__auth'
|
||||||
|
).annotate(rank=Window(
|
||||||
expression=Rank(),
|
expression=Rank(),
|
||||||
order_by=[F('total_points').desc(), 'junior__created_at']
|
order_by=[F('total_points').desc(), 'junior__created_at'])
|
||||||
)).order_by('-total_points', 'junior__created_at')
|
).order_by('-total_points', 'junior__created_at')
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
|
@ -22,7 +22,7 @@ from account.models import UserEmailOtp, UserNotification
|
|||||||
from junior.utils import junior_notification_email, junior_approval_mail, get_junior_leaderboard_rank
|
from junior.utils import junior_notification_email, junior_approval_mail, get_junior_leaderboard_rank
|
||||||
from guardian.utils import real_time, update_referral_points, convert_timedelta_into_datetime
|
from guardian.utils import real_time, update_referral_points, convert_timedelta_into_datetime
|
||||||
from notifications.utils import send_notification
|
from notifications.utils import send_notification
|
||||||
from notifications.constants import (ASSOCIATE_REQUEST, JUNIOR_ADDED, TASK_ACTION,
|
from notifications.constants import (ASSOCIATE_REQUEST, ASSOCIATE_JUNIOR, TASK_ACTION,
|
||||||
)
|
)
|
||||||
from web_admin.models import ArticleCard
|
from web_admin.models import ArticleCard
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ class AddJuniorSerializer(serializers.ModelSerializer):
|
|||||||
"""Notification email"""
|
"""Notification email"""
|
||||||
junior_notification_email.delay(email, full_name, email, password)
|
junior_notification_email.delay(email, full_name, email, password)
|
||||||
# push notification
|
# push notification
|
||||||
send_notification.delay(JUNIOR_ADDED, None, None, junior_data.auth.id, {})
|
send_notification.delay(ASSOCIATE_JUNIOR, None, None, junior_data.auth.id, {})
|
||||||
return junior_data
|
return junior_data
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +70,9 @@ def get_junior_leaderboard_rank(junior_obj):
|
|||||||
:param junior_obj:
|
:param junior_obj:
|
||||||
:return: junior's position/rank
|
:return: junior's position/rank
|
||||||
"""
|
"""
|
||||||
queryset = JuniorPoints.objects.select_related('junior', 'junior__auth').annotate(rank=Window(
|
queryset = JuniorPoints.objects.filter(
|
||||||
|
junior__is_verified=True
|
||||||
|
).select_related('junior', 'junior__auth').annotate(rank=Window(
|
||||||
expression=Rank(),
|
expression=Rank(),
|
||||||
order_by=[F('total_points').desc(), 'junior__created_at']
|
order_by=[F('total_points').desc(), 'junior__created_at']
|
||||||
)).order_by('-total_points', 'junior__created_at')
|
)).order_by('-total_points', 'junior__created_at')
|
||||||
|
@ -42,12 +42,12 @@ from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, Ad
|
|||||||
from guardian.models import Guardian, JuniorTask
|
from guardian.models import Guardian, JuniorTask
|
||||||
from guardian.serializers import TaskDetailsSerializer, TaskDetailsjuniorSerializer
|
from guardian.serializers import TaskDetailsSerializer, TaskDetailsjuniorSerializer
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
from base.constants import NUMBER, ARTICLE_STATUS, none
|
from base.constants import NUMBER, ARTICLE_STATUS, none, GUARDIAN
|
||||||
from account.utils import custom_response, custom_error_response
|
from account.utils import custom_response, custom_error_response
|
||||||
from guardian.utils import upload_image_to_alibaba
|
from guardian.utils import upload_image_to_alibaba
|
||||||
from .utils import update_positions_based_on_points
|
from .utils import update_positions_based_on_points
|
||||||
from notifications.utils import send_notification
|
from notifications.utils import send_notification
|
||||||
from notifications.constants import REMOVE_JUNIOR, ARTICLE_REWARD_POINTS
|
from notifications.constants import REMOVE_JUNIOR, ARTICLE_REWARD_POINTS, ASSOCIATE_EXISTING_JUNIOR
|
||||||
from web_admin.models import Article, ArticleSurvey, SurveyOption, ArticleCard
|
from web_admin.models import Article, ArticleSurvey, SurveyOption, ArticleCard
|
||||||
from web_admin.serializers.article_serializer import (ArticleSerializer, ArticleListSerializer,
|
from web_admin.serializers.article_serializer import (ArticleSerializer, ArticleListSerializer,
|
||||||
StartAssessmentSerializer)
|
StartAssessmentSerializer)
|
||||||
@ -229,6 +229,7 @@ class AddJuniorAPIView(viewsets.ModelViewSet):
|
|||||||
if jun_data:
|
if jun_data:
|
||||||
jun_data.relationship = str(self.request.data['relationship'])
|
jun_data.relationship = str(self.request.data['relationship'])
|
||||||
jun_data.save()
|
jun_data.save()
|
||||||
|
send_notification.delay(ASSOCIATE_EXISTING_JUNIOR, self.request.user.id, GUARDIAN, junior.auth.id, {})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,19 +6,20 @@ ASSOCIATE_REQUEST = 3
|
|||||||
ASSOCIATE_REJECTED = 4
|
ASSOCIATE_REJECTED = 4
|
||||||
ASSOCIATE_APPROVED = 5
|
ASSOCIATE_APPROVED = 5
|
||||||
REFERRAL_POINTS = 6
|
REFERRAL_POINTS = 6
|
||||||
JUNIOR_ADDED = 7
|
ASSOCIATE_JUNIOR = 7
|
||||||
|
ASSOCIATE_EXISTING_JUNIOR = 8
|
||||||
|
|
||||||
TASK_ASSIGNED = 8
|
TASK_ASSIGNED = 9
|
||||||
TASK_ACTION = 9
|
TASK_ACTION = 10
|
||||||
TASK_REJECTED = 10
|
TASK_REJECTED = 11
|
||||||
TASK_APPROVED = 11
|
TASK_APPROVED = 12
|
||||||
PENDING_TASK_EXPIRING = 12
|
PENDING_TASK_EXPIRING = 13
|
||||||
IN_PROGRESS_TASK_EXPIRING = 13
|
IN_PROGRESS_TASK_EXPIRING = 14
|
||||||
TOP_JUNIOR = 14
|
TOP_JUNIOR = 15
|
||||||
|
|
||||||
NEW_ARTICLE_PUBLISHED = 15
|
NEW_ARTICLE_PUBLISHED = 16
|
||||||
ARTICLE_REWARD_POINTS = 16
|
ARTICLE_REWARD_POINTS = 17
|
||||||
REMOVE_JUNIOR = 17
|
REMOVE_JUNIOR = 18
|
||||||
|
|
||||||
TEST_NOTIFICATION = 99
|
TEST_NOTIFICATION = 99
|
||||||
|
|
||||||
@ -53,10 +54,14 @@ NOTIFICATION_DICT = {
|
|||||||
},
|
},
|
||||||
# Juniors will receive notification
|
# Juniors will receive notification
|
||||||
# once any custodians add them in their account
|
# once any custodians add them in their account
|
||||||
JUNIOR_ADDED: {
|
ASSOCIATE_JUNIOR: {
|
||||||
"title": "Profile already setup!",
|
"title": "Profile already setup!",
|
||||||
"body": "Your guardian has already setup your profile."
|
"body": "Your guardian has already setup your profile."
|
||||||
},
|
},
|
||||||
|
ASSOCIATE_EXISTING_JUNIOR: {
|
||||||
|
"title": "Associated to guardian",
|
||||||
|
"body": "Your are associated to your guardian {from_user}."
|
||||||
|
},
|
||||||
# Juniors will receive Notification
|
# Juniors will receive Notification
|
||||||
# for every Task Assign by Custodians
|
# for every Task Assign by Custodians
|
||||||
TASK_ASSIGNED: {
|
TASK_ASSIGNED: {
|
||||||
|
@ -128,7 +128,9 @@ class AnalyticsViewSet(GenericViewSet):
|
|||||||
:param request:
|
:param request:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
queryset = JuniorPoints.objects.select_related('junior', 'junior__auth').annotate(rank=Window(
|
queryset = JuniorPoints.objects.filter(
|
||||||
|
junior__is_verified=True
|
||||||
|
).select_related('junior', 'junior__auth').annotate(rank=Window(
|
||||||
expression=Rank(),
|
expression=Rank(),
|
||||||
order_by=[F('total_points').desc(), 'junior__created_at']
|
order_by=[F('total_points').desc(), 'junior__created_at']
|
||||||
)).order_by('-total_points', 'junior__created_at')
|
)).order_by('-total_points', 'junior__created_at')
|
||||||
@ -199,7 +201,9 @@ class AnalyticsViewSet(GenericViewSet):
|
|||||||
|
|
||||||
# sheet 3 for Juniors Leaderboard and rank
|
# sheet 3 for Juniors Leaderboard and rank
|
||||||
elif sheet_name == 'Juniors Leaderboard':
|
elif sheet_name == 'Juniors Leaderboard':
|
||||||
queryset = JuniorPoints.objects.select_related('junior', 'junior__auth').annotate(rank=Window(
|
queryset = JuniorPoints.objects.filter(
|
||||||
|
junior__is_verified=True
|
||||||
|
).select_related('junior', 'junior__auth').annotate(rank=Window(
|
||||||
expression=Rank(),
|
expression=Rank(),
|
||||||
order_by=[F('total_points').desc(), 'junior__created_at']
|
order_by=[F('total_points').desc(), 'junior__created_at']
|
||||||
)).order_by('-total_points', 'junior__created_at')[:15]
|
)).order_by('-total_points', 'junior__created_at')[:15]
|
||||||
|
Reference in New Issue
Block a user