mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-27 17:14:55 +00:00
Merge pull request #156 from KiwiTechLLC/sprint4
guardian list api changes
This commit is contained in:
@ -70,6 +70,12 @@ SIGNUP_METHODS = (
|
|||||||
('2', 'google'),
|
('2', 'google'),
|
||||||
('3', 'apple')
|
('3', 'apple')
|
||||||
)
|
)
|
||||||
|
# guardian code status
|
||||||
|
GUARDIAN_CODE_STATUS = (
|
||||||
|
('1', 'no guardian code'),
|
||||||
|
('2', 'exist guardian code'),
|
||||||
|
('3', 'request for guardian code')
|
||||||
|
)
|
||||||
# relationship
|
# relationship
|
||||||
RELATIONSHIP = (
|
RELATIONSHIP = (
|
||||||
('1', 'parent'),
|
('1', 'parent'),
|
||||||
|
|||||||
@ -403,11 +403,20 @@ class GuardianDetailListSerializer(serializers.ModelSerializer):
|
|||||||
email = serializers.SerializerMethodField('get_email')
|
email = serializers.SerializerMethodField('get_email')
|
||||||
image = serializers.SerializerMethodField('get_image')
|
image = serializers.SerializerMethodField('get_image')
|
||||||
guardian_id = serializers.SerializerMethodField('get_guardian_id')
|
guardian_id = serializers.SerializerMethodField('get_guardian_id')
|
||||||
|
guardian_code = serializers.SerializerMethodField('get_guardian_code')
|
||||||
|
gender = serializers.SerializerMethodField('get_gender')
|
||||||
|
phone = serializers.SerializerMethodField('get_phone')
|
||||||
|
country_name = serializers.SerializerMethodField('get_country_name')
|
||||||
|
dob = serializers.SerializerMethodField('get_dob')
|
||||||
|
guardian_code_status = serializers.SerializerMethodField('get_guardian_code_status')
|
||||||
|
# code info
|
||||||
|
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
"""Meta info"""
|
"""Meta info"""
|
||||||
model = JuniorGuardianRelationship
|
model = JuniorGuardianRelationship
|
||||||
fields = ['guardian_id', 'first_name', 'last_name', 'email', 'relationship', 'image', 'created_at',
|
fields = ['guardian_id', 'first_name', 'last_name', 'email', 'relationship', 'image', 'dob',
|
||||||
|
'guardian_code', 'gender', 'phone', 'country_name', 'created_at', 'guardian_code_status',
|
||||||
'updated_at']
|
'updated_at']
|
||||||
|
|
||||||
def get_guardian_id(self,obj):
|
def get_guardian_id(self,obj):
|
||||||
@ -422,9 +431,33 @@ class GuardianDetailListSerializer(serializers.ModelSerializer):
|
|||||||
return obj.guardian.user.last_name
|
return obj.guardian.user.last_name
|
||||||
|
|
||||||
def get_email(self,obj):
|
def get_email(self,obj):
|
||||||
"""emailof guardian"""
|
"""email of guardian"""
|
||||||
return obj.guardian.user.email
|
return obj.guardian.user.email
|
||||||
|
|
||||||
def get_image(self,obj):
|
def get_image(self,obj):
|
||||||
"""first name of guardian"""
|
"""guardian image"""
|
||||||
return obj.guardian.image
|
return obj.guardian.image
|
||||||
|
|
||||||
|
def get_guardian_code(self,obj):
|
||||||
|
""" guardian code"""
|
||||||
|
return obj.guardian.guardian_code
|
||||||
|
|
||||||
|
def get_gender(self,obj):
|
||||||
|
""" guardian gender"""
|
||||||
|
return obj.guardian.gender
|
||||||
|
|
||||||
|
def get_phone(self,obj):
|
||||||
|
"""guardian phone"""
|
||||||
|
return obj.guardian.phone
|
||||||
|
|
||||||
|
def get_country_name(self,obj):
|
||||||
|
""" guardian country name """
|
||||||
|
return obj.guardian.country_name
|
||||||
|
|
||||||
|
def get_dob(self,obj):
|
||||||
|
"""guardian dob """
|
||||||
|
return obj.guardian.dob
|
||||||
|
|
||||||
|
def get_guardian_code_status(self,obj):
|
||||||
|
"""guardian code status"""
|
||||||
|
return obj.junior.guardian_code_status
|
||||||
|
|||||||
@ -36,7 +36,7 @@ from account.models import UserEmailOtp, UserNotification
|
|||||||
from .tasks import generate_otp
|
from .tasks import generate_otp
|
||||||
from account.utils import custom_response, custom_error_response, OTP_EXPIRY, send_otp_email
|
from account.utils import custom_response, custom_error_response, OTP_EXPIRY, send_otp_email
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
from base.constants import NUMBER
|
from base.constants import NUMBER, GUARDIAN_CODE_STATUS
|
||||||
from .utils import upload_image_to_alibaba
|
from .utils import upload_image_to_alibaba
|
||||||
from notifications.constants import REGISTRATION, TASK_CREATED, LEADERBOARD_RANKING
|
from notifications.constants import REGISTRATION, TASK_CREATED, LEADERBOARD_RANKING
|
||||||
from notifications.utils import send_notification
|
from notifications.utils import send_notification
|
||||||
@ -379,6 +379,6 @@ class GuardianListAPIView(viewsets.ModelViewSet):
|
|||||||
# use GuardianDetailListSerializer serializer
|
# use GuardianDetailListSerializer serializer
|
||||||
serializer = GuardianDetailListSerializer(guardian_data, many=True)
|
serializer = GuardianDetailListSerializer(guardian_data, many=True)
|
||||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||||
return custom_response(ERROR_CODE['2068'], response_status=status.HTTP_200_OK)
|
return custom_response({"status": GUARDIAN_CODE_STATUS['1']},response_status=status.HTTP_200_OK)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|||||||
18
junior/migrations/0020_junior_guardian_code_status.py
Normal file
18
junior/migrations/0020_junior_guardian_code_status.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-08-08 05:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('junior', '0019_juniorarticlepoints'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='junior',
|
||||||
|
name='guardian_code_status',
|
||||||
|
field=models.CharField(blank=True, choices=[('1', 'no guardian code'), ('2', 'exist guardian code'), ('3', 'request for guardian code')], default='1', max_length=31, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -6,7 +6,7 @@ from django.contrib.auth import get_user_model
|
|||||||
"""Import ArrayField"""
|
"""Import ArrayField"""
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
"""Import django app"""
|
"""Import django app"""
|
||||||
from base.constants import GENDERS, SIGNUP_METHODS, RELATIONSHIP
|
from base.constants import GENDERS, SIGNUP_METHODS, RELATIONSHIP, GUARDIAN_CODE_STATUS
|
||||||
# Import guardian's model
|
# Import guardian's model
|
||||||
from guardian.models import Guardian
|
from guardian.models import Guardian
|
||||||
# Import web admin's model
|
# Import web admin's model
|
||||||
@ -74,6 +74,9 @@ class Junior(models.Model):
|
|||||||
is_verified = models.BooleanField(default=False)
|
is_verified = models.BooleanField(default=False)
|
||||||
"""guardian code is approved or not"""
|
"""guardian code is approved or not"""
|
||||||
guardian_code_approved = models.BooleanField(default=False)
|
guardian_code_approved = models.BooleanField(default=False)
|
||||||
|
# guardian code status"""
|
||||||
|
guardian_code_status = models.CharField(max_length=31, choices=GUARDIAN_CODE_STATUS, default='1',
|
||||||
|
null=True, blank=True)
|
||||||
# Profile created and updated time"""
|
# Profile created and updated time"""
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
updated_at = models.DateTimeField(auto_now=True)
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
|||||||
@ -15,7 +15,8 @@ from account.utils import send_otp_email, generate_code
|
|||||||
from junior.models import Junior, JuniorPoints, JuniorGuardianRelationship
|
from junior.models import Junior, JuniorPoints, JuniorGuardianRelationship
|
||||||
from guardian.tasks import generate_otp
|
from guardian.tasks import generate_otp
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
from base.constants import PENDING, IN_PROGRESS, REJECTED, REQUESTED, COMPLETED, NUMBER, JUN, ZOD, EXPIRED
|
from base.constants import (PENDING, IN_PROGRESS, REJECTED, REQUESTED, COMPLETED, NUMBER, JUN, ZOD, EXPIRED,
|
||||||
|
GUARDIAN_CODE_STATUS)
|
||||||
from guardian.models import Guardian, JuniorTask
|
from guardian.models import Guardian, JuniorTask
|
||||||
from account.models import UserEmailOtp, UserNotification
|
from account.models import UserEmailOtp, UserNotification
|
||||||
from junior.utils import junior_notification_email, junior_approval_mail
|
from junior.utils import junior_notification_email, junior_approval_mail
|
||||||
@ -283,7 +284,8 @@ class AddJuniorSerializer(serializers.ModelSerializer):
|
|||||||
junior_code=generate_code(JUN, user_data.id),
|
junior_code=generate_code(JUN, user_data.id),
|
||||||
referral_code=generate_code(ZOD, user_data.id),
|
referral_code=generate_code(ZOD, user_data.id),
|
||||||
referral_code_used=guardian_data.referral_code,
|
referral_code_used=guardian_data.referral_code,
|
||||||
is_password_set=False, is_verified=True)
|
is_password_set=False, is_verified=True,
|
||||||
|
guardian_code_status=GUARDIAN_CODE_STATUS['2'])
|
||||||
JuniorGuardianRelationship.objects.create(guardian=guardian_data, junior=junior_data,
|
JuniorGuardianRelationship.objects.create(guardian=guardian_data, junior=junior_data,
|
||||||
relationship=relationship)
|
relationship=relationship)
|
||||||
"""Generate otp"""
|
"""Generate otp"""
|
||||||
@ -403,13 +405,15 @@ class AddGuardianSerializer(serializers.ModelSerializer):
|
|||||||
relationship = self.context['relationship']
|
relationship = self.context['relationship']
|
||||||
full_name = self.context['first_name'] + ' ' + self.context['last_name']
|
full_name = self.context['first_name'] + ' ' + self.context['last_name']
|
||||||
junior_data = Junior.objects.filter(auth__username=junior).last()
|
junior_data = Junior.objects.filter(auth__username=junior).last()
|
||||||
|
junior_data.guardian_code_status = GUARDIAN_CODE_STATUS['3']
|
||||||
|
junior_data.save()
|
||||||
instance = User.objects.filter(username=email).last()
|
instance = User.objects.filter(username=email).last()
|
||||||
if instance:
|
if instance:
|
||||||
guardian_data = Guardian.objects.filter(user=instance).update(is_invited=True,
|
guardian_data = Guardian.objects.filter(user=instance).update(is_invited=True,
|
||||||
referral_code=generate_code(ZOD,
|
referral_code=generate_code(ZOD,
|
||||||
instance.id),
|
instance.id),
|
||||||
referral_code_used=junior_data.referral_code,
|
referral_code_used=junior_data.referral_code,
|
||||||
is_verified=True)
|
is_verified=True)
|
||||||
UserNotification.objects.get_or_create(user=instance)
|
UserNotification.objects.get_or_create(user=instance)
|
||||||
return guardian_data
|
return guardian_data
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -221,15 +221,20 @@ class ArticleListSerializer(serializers.ModelSerializer):
|
|||||||
"""
|
"""
|
||||||
article_cards = ArticleCardSerializer(many=True)
|
article_cards = ArticleCardSerializer(many=True)
|
||||||
total_points = serializers.SerializerMethodField('get_total_points')
|
total_points = serializers.SerializerMethodField('get_total_points')
|
||||||
|
is_completed = serializers.SerializerMethodField('get_is_completed')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""
|
"""
|
||||||
meta class
|
meta class
|
||||||
"""
|
"""
|
||||||
model = Article
|
model = Article
|
||||||
fields = ('id', 'title', 'description', 'article_cards', 'total_points')
|
fields = ('id', 'title', 'description', 'article_cards', 'total_points', 'is_completed')
|
||||||
|
|
||||||
def get_total_points(self, obj):
|
def get_total_points(self, obj):
|
||||||
"""total points of article"""
|
"""total points of article"""
|
||||||
total_question = ArticleSurvey.objects.filter(article=obj).count()
|
total_question = ArticleSurvey.objects.filter(article=obj).count()
|
||||||
return total_question * 5
|
return total_question * NUMBER['five']
|
||||||
|
|
||||||
|
def get_is_completed(self, obj):
|
||||||
|
"""complete all question"""
|
||||||
|
return False
|
||||||
Reference in New Issue
Block a user