Merge pull request #223 from KiwiTechLLC/ZBKADM-72

csv/excel method changed, uploading to alibaba cloud and providing li…
This commit is contained in:
dilipshrivastwa-kiwi
2023-08-18 13:47:36 +05:30
committed by GitHub
5 changed files with 56 additions and 39 deletions
@@ -92,10 +92,7 @@ class UserCSVReportSerializer(serializers.ModelSerializer):
: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():
if profile := (obj.guardian_profile.all().first() or obj.junior_profile.all().first()):
return f"+{profile.country_code}{profile.phone}" \
if profile.country_code and profile.phone else profile.phone
else:
@@ -120,9 +117,7 @@ class UserCSVReportSerializer(serializers.ModelSerializer):
: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():
if profile := (obj.guardian_profile.all().first() or obj.junior_profile.all().first()):
return "Active" if profile.is_active else "Inactive"
@staticmethod
@@ -5,7 +5,7 @@ web_admin user_management serializers file
from rest_framework import serializers
from django.contrib.auth import get_user_model
from base.constants import USER_TYPE
from base.constants import USER_TYPE, GUARDIAN, JUNIOR
# local imports
from base.messages import ERROR_CODE, SUCCESS_CODE
from guardian.models import Guardian
@@ -210,10 +210,10 @@ class JuniorSerializer(serializers.ModelSerializer):
"""
instance.auth.email = self.validated_data.get('email', instance.auth.email)
instance.auth.username = self.validated_data.get('email', instance.auth.username)
instance.auth.save()
instance.auth.save(update_fields=['email', 'username'])
instance.country_code = validated_data.get('country_code', instance.country_code)
instance.phone = validated_data.get('phone', instance.phone)
instance.save()
instance.save(update_fields=['country_code', 'phone'])
return instance
@staticmethod
@@ -265,33 +265,30 @@ class UserManagementDetailSerializer(serializers.ModelSerializer):
model = USER
fields = ('id', 'user_type', 'email', 'guardian_profile', 'junior_profile', 'associated_users')
@staticmethod
def get_user_type(obj):
def get_user_type(self, 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
return GUARDIAN if self.context['user_type'] == GUARDIAN else JUNIOR
@staticmethod
def get_associated_users(obj):
def get_associated_users(self, obj):
"""
:param obj: user object
:return: associated user
"""
if profile := obj.guardian_profile.all().first():
if self.context['user_type'] == GUARDIAN:
profile = obj.guardian_profile.all().only('user_id', 'guardian_code').first()
if profile.guardian_code:
junior = Junior.objects.filter(guardian_code__contains=[profile.guardian_code], is_verified=True)
junior = Junior.objects.filter(guardian_code__contains=[profile.guardian_code],
is_verified=True).select_related('auth')
serializer = JuniorSerializer(junior, many=True)
return serializer.data
elif profile := obj.junior_profile.all().first():
elif self.context['user_type'] == JUNIOR:
profile = obj.junior_profile.all().only('auth_id', 'guardian_code').first()
if profile.guardian_code:
guardian = Guardian.objects.filter(guardian_code__in=profile.guardian_code, is_verified=True)
guardian = Guardian.objects.filter(guardian_code__in=profile.guardian_code,
is_verified=True).select_related('user')
serializer = GuardianSerializer(guardian, many=True)
return serializer.data
else: