mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 18:07:02 +00:00
csv/xls report
This commit is contained in:
@ -2,11 +2,20 @@
|
||||
web_admin analytics serializer file
|
||||
"""
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from base.constants import USER_TYPE
|
||||
|
||||
from junior.models import JuniorPoints, Junior
|
||||
from web_admin.serializers.user_management_serializer import JuniorSerializer, GuardianSerializer
|
||||
|
||||
USER = get_user_model()
|
||||
|
||||
|
||||
class JuniorLeaderboardSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
junior leaderboard serializer
|
||||
"""
|
||||
name = serializers.SerializerMethodField()
|
||||
first_name = serializers.SerializerMethodField()
|
||||
last_name = serializers.SerializerMethodField()
|
||||
@ -44,9 +53,70 @@ class JuniorLeaderboardSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class LeaderboardSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
leaderboard serializer
|
||||
"""
|
||||
junior = JuniorLeaderboardSerializer()
|
||||
rank = serializers.IntegerField()
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
meta class
|
||||
"""
|
||||
model = JuniorPoints
|
||||
fields = ('total_points', 'rank', 'junior')
|
||||
|
||||
|
||||
class UserCSVReportSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
user csv/xls report serializer
|
||||
"""
|
||||
phone_number = serializers.SerializerMethodField()
|
||||
user_type = serializers.SerializerMethodField()
|
||||
is_active = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
meta class
|
||||
"""
|
||||
model = USER
|
||||
fields = ('first_name', 'last_name', 'email', 'phone_number', 'user_type', 'is_active', 'date_joined')
|
||||
|
||||
@staticmethod
|
||||
def get_phone_number(obj):
|
||||
"""
|
||||
:param obj: user object
|
||||
:return: user phone number
|
||||
"""
|
||||
if profile := obj.guardian_profile.all().first():
|
||||
return f"+{profile.country_code}{profile.phone}" \
|
||||
if profile.country_code and profile.phone else profile.phone
|
||||
elif profile := obj.junior_profile.all().first():
|
||||
return f"+{profile.country_code}{profile.phone}" \
|
||||
if profile.country_code and profile.phone else profile.phone
|
||||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_user_type(obj):
|
||||
"""
|
||||
:param obj: user object
|
||||
:return: user type
|
||||
"""
|
||||
if obj.guardian_profile.all().first():
|
||||
return dict(USER_TYPE).get('2')
|
||||
elif obj.junior_profile.all().first():
|
||||
return dict(USER_TYPE).get('1')
|
||||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_is_active(obj):
|
||||
"""
|
||||
:param obj: user object
|
||||
:return: user type
|
||||
"""
|
||||
if profile := obj.guardian_profile.all().first():
|
||||
return "Active" if profile.is_active else "Inactive"
|
||||
elif profile := obj.junior_profile.all().first():
|
||||
return "Active" if profile.is_active else "Inactive"
|
||||
|
Reference in New Issue
Block a user