mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-17 02:45:08 +00:00
update position of the junior
This commit is contained in:
@ -3,7 +3,8 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
"""Third party Django app"""
|
"""Third party Django app"""
|
||||||
from templated_email import send_templated_mail
|
from templated_email import send_templated_mail
|
||||||
|
from .models import JuniorPoints
|
||||||
|
from django.db.models import F
|
||||||
# junior notification
|
# junior notification
|
||||||
# email for sending email
|
# email for sending email
|
||||||
# when guardian create junior profile
|
# when guardian create junior profile
|
||||||
@ -45,3 +46,14 @@ def junior_approval_mail(guardian, full_name):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
return full_name
|
return full_name
|
||||||
|
|
||||||
|
def update_positions_based_on_points():
|
||||||
|
# First, retrieve all the JuniorPoints instances ordered by total_points in descending order.
|
||||||
|
juniors_points = JuniorPoints.objects.order_by('-total_points')
|
||||||
|
|
||||||
|
# Now, iterate through the queryset and update the position field based on the order.
|
||||||
|
position = 1
|
||||||
|
for junior_point in juniors_points:
|
||||||
|
junior_point.position = position
|
||||||
|
junior_point.save()
|
||||||
|
position += 1
|
||||||
|
@ -19,7 +19,7 @@ import requests
|
|||||||
# Import account's serializer
|
# Import account's serializer
|
||||||
# Import account's task
|
# Import account's task
|
||||||
# import junior serializer
|
# import junior serializer
|
||||||
from junior.models import Junior
|
from junior.models import Junior, JuniorPoints
|
||||||
from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, AddJuniorSerializer,\
|
from .serializers import (CreateJuniorSerializer, JuniorDetailListSerializer, AddJuniorSerializer,\
|
||||||
RemoveJuniorSerializer, CompleteTaskSerializer, JuniorPointsSerializer)
|
RemoveJuniorSerializer, CompleteTaskSerializer, JuniorPointsSerializer)
|
||||||
from guardian.models import Guardian, JuniorTask
|
from guardian.models import Guardian, JuniorTask
|
||||||
@ -28,6 +28,7 @@ from base.messages import ERROR_CODE, SUCCESS_CODE
|
|||||||
from base.constants import NUMBER
|
from base.constants import NUMBER
|
||||||
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
|
||||||
|
|
||||||
""" Define APIs """
|
""" Define APIs """
|
||||||
# Define validate guardian code API,
|
# Define validate guardian code API,
|
||||||
@ -97,20 +98,7 @@ class JuniorListAPIView(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
""" junior list"""
|
""" junior list"""
|
||||||
print("self.request.META====>",self.request.META)
|
update_positions_based_on_points()
|
||||||
print()
|
|
||||||
auth_token = self.request.META['HTTP_AUTHORIZATION']
|
|
||||||
headers_token = {
|
|
||||||
'Authorization': auth_token
|
|
||||||
}
|
|
||||||
print("auth_token====>", auth_token)
|
|
||||||
print("headers_token====>", headers_token)
|
|
||||||
print("os.getenv('BASE_URL')===>", os.getenv('BASE_URL'))
|
|
||||||
print("url====>", os.getenv('BASE_URL') + '/api/v1/top-junior/')
|
|
||||||
# url = requests.get(os.getenv('BASE_URL') + '/api/v1/top-junior/', headers=headers_token)
|
|
||||||
# print("url data====>",url)
|
|
||||||
|
|
||||||
# requests.get('https://dev-api.zodqaapp.com/api/v1/top-junior/', headers=headers_token)
|
|
||||||
guardian_data = Guardian.objects.filter(user__email=request.user).last()
|
guardian_data = Guardian.objects.filter(user__email=request.user).last()
|
||||||
# fetch junior object
|
# fetch junior object
|
||||||
if guardian_data:
|
if guardian_data:
|
||||||
@ -149,7 +137,7 @@ class InvitedJuniorAPIView(viewsets.ModelViewSet):
|
|||||||
"""Get the queryset for the view"""
|
"""Get the queryset for the view"""
|
||||||
guardian = Guardian.objects.filter(user__email=self.request.user).last()
|
guardian = Guardian.objects.filter(user__email=self.request.user).last()
|
||||||
junior_queryset = Junior.objects.filter(guardian_code__icontains=str(guardian.guardian_code),
|
junior_queryset = Junior.objects.filter(guardian_code__icontains=str(guardian.guardian_code),
|
||||||
is_invited=True)
|
is_invited=True)
|
||||||
return junior_queryset
|
return junior_queryset
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
""" junior list"""
|
""" junior list"""
|
||||||
@ -292,12 +280,7 @@ class JuniorPointsListAPIView(viewsets.ModelViewSet):
|
|||||||
"""profile view"""
|
"""profile view"""
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
# update position of junior
|
# update position of junior
|
||||||
token = self.request.META['HTTP_AUTHORIZATION']
|
update_positions_based_on_points()
|
||||||
headers = {
|
|
||||||
'Authorization': token
|
|
||||||
}
|
|
||||||
# requests.get(os.getenv('BASE_URL') + '/api/v1/top-junior/', headers=headers)
|
|
||||||
# requests.get('https://dev-api.zodqaapp.com/api/v1/top-junior/', headers=headers)
|
|
||||||
serializer = JuniorPointsSerializer(queryset)
|
serializer = JuniorPointsSerializer(queryset)
|
||||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user