mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 10:26:16 +00:00
jira-15 leader board API and profile API
This commit is contained in:
@ -120,7 +120,7 @@ class CreateGuardianSerializer(serializers.ModelSerializer):
|
||||
image_url = upload_image_to_alibaba(image, filename)
|
||||
guardian.image = image_url
|
||||
"""Complete profile of the junior if below all data are filled"""
|
||||
complete_profile_field = all([guardian.phone, guardian.gender, guardian.family_name, guardian.country_name,
|
||||
complete_profile_field = all([guardian.phone, guardian.gender, guardian.country_name,
|
||||
guardian.dob, guardian.country_code, user.first_name, user.last_name,
|
||||
user.email, guardian.image])
|
||||
guardian.is_complete_profile = False
|
||||
@ -188,18 +188,18 @@ class TaskDetailsSerializer(serializers.ModelSerializer):
|
||||
class TopJuniorSerializer(serializers.ModelSerializer):
|
||||
"""Top junior serializer"""
|
||||
junior = JuniorDetailSerializer()
|
||||
position = serializers.SerializerMethodField()
|
||||
position = serializers.IntegerField()
|
||||
|
||||
class Meta(object):
|
||||
class Meta:
|
||||
"""Meta info"""
|
||||
model = JuniorPoints
|
||||
fields = ['id', 'junior', 'total_task_points', 'position', 'created_at', 'updated_at']
|
||||
|
||||
def get_position(self, obj):
|
||||
"""get position of junior"""
|
||||
queryset = self.context['view'].get_queryset()
|
||||
position = list(queryset).index(obj) + 1
|
||||
return position
|
||||
def to_representation(self, instance):
|
||||
"""Convert instance to representation"""
|
||||
representation = super().to_representation(instance)
|
||||
representation['position'] = instance.position
|
||||
return representation
|
||||
|
||||
|
||||
class GuardianProfileSerializer(serializers.ModelSerializer):
|
||||
|
@ -143,7 +143,7 @@ class SearchTaskListAPIView(viewsets.ModelViewSet):
|
||||
class TopJuniorListAPIView(viewsets.ModelViewSet):
|
||||
"""Top juniors list"""
|
||||
serializer_class = TopJuniorSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
# permission_classes = [IsAuthenticated]
|
||||
queryset = JuniorPoints.objects.all()
|
||||
|
||||
def get_serializer_context(self):
|
||||
@ -152,8 +152,14 @@ class TopJuniorListAPIView(viewsets.ModelViewSet):
|
||||
return context
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
"""fetch junior list those complete their task"""
|
||||
"""Fetch junior list of those who complete their tasks"""
|
||||
junior_total_points = self.get_queryset().order_by('-total_task_points')
|
||||
|
||||
# Update the position field for each JuniorPoints object
|
||||
for index, junior in enumerate(junior_total_points):
|
||||
junior.position = index + 1
|
||||
junior.save()
|
||||
|
||||
serializer = self.get_serializer(junior_total_points, many=True)
|
||||
return custom_response(serializer.data, response_status=status.HTTP_200_OK)
|
||||
|
||||
|
@ -16,7 +16,7 @@ class JuniorAdmin(admin.ModelAdmin):
|
||||
@admin.register(JuniorPoints)
|
||||
class JuniorPointsAdmin(admin.ModelAdmin):
|
||||
"""Junior Points Admin"""
|
||||
list_display = ['junior', 'total_task_points']
|
||||
list_display = ['junior', 'total_task_points', 'position']
|
||||
|
||||
def __str__(self):
|
||||
"""Return email id"""
|
||||
|
18
junior/migrations/0009_juniorpoints_position.py
Normal file
18
junior/migrations/0009_juniorpoints_position.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.2 on 2023-07-10 07:36
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('junior', '0008_juniorpoints'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='juniorpoints',
|
||||
name='position',
|
||||
field=models.IntegerField(blank=True, default=99999, null=True),
|
||||
),
|
||||
]
|
@ -47,6 +47,8 @@ class JuniorPoints(models.Model):
|
||||
junior = models.OneToOneField(Junior, on_delete=models.CASCADE, related_name='junior_points')
|
||||
"""Contact details"""
|
||||
total_task_points = models.IntegerField(blank=True, null=True, default=0)
|
||||
"""position of the junior"""
|
||||
position = models.IntegerField(blank=True, null=True, default=99999)
|
||||
"""Profile created and updated time"""
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
@ -5,7 +5,7 @@ from django.contrib.auth.models import User
|
||||
from django.db import transaction
|
||||
import random
|
||||
"""Import django app"""
|
||||
from junior.models import Junior
|
||||
from junior.models import Junior, JuniorPoints
|
||||
from guardian.utils import upload_image_to_alibaba
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from guardian.models import Guardian, JuniorTask
|
||||
@ -147,6 +147,7 @@ class JuniorDetailListSerializer(serializers.ModelSerializer):
|
||||
requested_task = serializers.SerializerMethodField('get_requested_task')
|
||||
rejected_task = serializers.SerializerMethodField('get_rejected_task')
|
||||
pending_task = serializers.SerializerMethodField('get_pending_task')
|
||||
position = serializers.SerializerMethodField('get_position')
|
||||
|
||||
|
||||
def get_auth(self, obj):
|
||||
@ -162,6 +163,11 @@ class JuniorDetailListSerializer(serializers.ModelSerializer):
|
||||
data = JuniorTask.objects.filter(junior=obj).count()
|
||||
return data
|
||||
|
||||
def get_position(self, obj):
|
||||
data = JuniorPoints.objects.filter(junior=obj).last()
|
||||
if data:
|
||||
return data.position
|
||||
return 99999
|
||||
def get_points(self, obj):
|
||||
data = sum(JuniorTask.objects.filter(junior=obj, task_status=COMPLETED).values_list('points', flat=True))
|
||||
return data
|
||||
@ -192,7 +198,7 @@ class JuniorDetailListSerializer(serializers.ModelSerializer):
|
||||
fields = ['id', 'email', 'first_name', 'last_name', 'country_code', 'phone', 'gender', 'dob',
|
||||
'guardian_code', 'referral_code','is_active', 'is_complete_profile', 'created_at', 'image',
|
||||
'updated_at', 'assigned_task','points', 'pending_task', 'in_progress_task', 'completed_task',
|
||||
'requested_task', 'rejected_task']
|
||||
'requested_task', 'rejected_task', 'position']
|
||||
|
||||
class JuniorProfileSerializer(serializers.ModelSerializer):
|
||||
"""junior serializer"""
|
||||
|
Reference in New Issue
Block a user