mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-23 09:27:57 +00:00
Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a41e3a6f14 | ||
|
|
7b02b7dfbc | ||
|
|
3852e9bf03 | ||
|
|
d208e5252c | ||
|
|
7b6d34f334 | ||
|
|
0006208cf8 | ||
|
|
352de6d630 | ||
|
|
ad582d77d7 | ||
|
|
019d028cb6 | ||
|
|
e1e5b1838a | ||
|
|
8ff142ce2f | ||
|
|
4537f1f4fa | ||
|
|
2086dcb472 | ||
|
|
d4eaaada74 | ||
|
|
396b4a32c3 | ||
|
|
232f082c77 | ||
|
|
aaa1730636 | ||
|
|
44b25dde3e | ||
|
|
b52819c033 | ||
|
|
9bd31f9e86 | ||
|
|
6374ea0a90 | ||
|
|
c115873972 |
+11
@@ -0,0 +1,11 @@
|
|||||||
|
FROM python:3.9
|
||||||
|
ENV PYTHONUNBUFFERED 1
|
||||||
|
RUN mkdir /usr/src/app
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
COPY . .
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install wkhtmltopdf -y
|
||||||
|
RUN apt install -y gdal-bin python3-gdal
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
|
"""Account admin"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
# Register your models here.
|
"""Import django app"""
|
||||||
from .models import UserProfile, UserEmailOtp, UserPhoneOtp
|
from .models import UserProfile, UserEmailOtp, UserPhoneOtp
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
@admin.register(UserProfile)
|
@admin.register(UserProfile)
|
||||||
class UserProfileAdmin(admin.ModelAdmin):
|
class UserProfileAdmin(admin.ModelAdmin):
|
||||||
|
"""User profile admin"""
|
||||||
list_display = ['user']
|
list_display = ['user']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -12,14 +14,18 @@ class UserProfileAdmin(admin.ModelAdmin):
|
|||||||
|
|
||||||
@admin.register(UserEmailOtp)
|
@admin.register(UserEmailOtp)
|
||||||
class UserEmailOtpAdmin(admin.ModelAdmin):
|
class UserEmailOtpAdmin(admin.ModelAdmin):
|
||||||
|
"""User Email otp admin"""
|
||||||
list_display = ['email']
|
list_display = ['email']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
"""Return object in email and otp format"""
|
||||||
return self.email + '-' + self.otp
|
return self.email + '-' + self.otp
|
||||||
|
|
||||||
@admin.register(UserPhoneOtp)
|
@admin.register(UserPhoneOtp)
|
||||||
class UserPhoneOtpAdmin(admin.ModelAdmin):
|
class UserPhoneOtpAdmin(admin.ModelAdmin):
|
||||||
|
"""User Phone otp admin"""
|
||||||
list_display = ['phone']
|
list_display = ['phone']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
"""Return object in phone number and otp format"""
|
||||||
return self.phone + '-' + self.otp
|
return self.phone + '-' + self.otp
|
||||||
@@ -13,6 +13,23 @@ from rest_framework.decorators import action
|
|||||||
from django.contrib.auth import authenticate, login
|
from django.contrib.auth import authenticate, login
|
||||||
from rest_framework_simplejwt.tokens import RefreshToken
|
from rest_framework_simplejwt.tokens import RefreshToken
|
||||||
|
|
||||||
|
class GoogleSignInSerializer(serializers.Serializer):
|
||||||
|
"""Google login Serializer"""
|
||||||
|
email = serializers.EmailField()
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
"""Create or update user model"""
|
||||||
|
with transaction.atomic():
|
||||||
|
print("validated_data====>",validated_data)
|
||||||
|
if User.objects.filter(email__iexact=self.validated_data['email']).exists():
|
||||||
|
return User.objects.get(email__iexact=self.validated_data['email'])
|
||||||
|
|
||||||
|
if not User.objects.filter(email__iexact=self.validated_data['email']).exists():
|
||||||
|
instance = User.objects.create(username=self.validated_data['email'],
|
||||||
|
email=self.validated_data['email'])
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
class ResetPasswordSerializer(serializers.Serializer):
|
class ResetPasswordSerializer(serializers.Serializer):
|
||||||
"""Reset Password after verification"""
|
"""Reset Password after verification"""
|
||||||
verification_code = serializers.CharField(max_length=10)
|
verification_code = serializers.CharField(max_length=10)
|
||||||
@@ -62,7 +79,6 @@ class ChangePasswordSerializer(serializers.Serializer):
|
|||||||
user_details.set_password(new_password)
|
user_details.set_password(new_password)
|
||||||
user_details.save()
|
user_details.save()
|
||||||
return {'password':new_password}
|
return {'password':new_password}
|
||||||
return user_details
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +11,8 @@ router = routers.SimpleRouter()
|
|||||||
|
|
||||||
"""API End points with router"""
|
"""API End points with router"""
|
||||||
router.register('user', UserLogin, basename='user')
|
router.register('user', UserLogin, basename='user')
|
||||||
router.register('superuser', UserLogin, basename='superuser')
|
router.register('admin', UserLogin, basename='admin')
|
||||||
|
# router.register('google-login', GoogleLoginAPIViewset, basename='admin')
|
||||||
router.register('send-phone-otp', SendPhoneOtp, basename='send-phone-otp')
|
router.register('send-phone-otp', SendPhoneOtp, basename='send-phone-otp')
|
||||||
router.register('user-phone-verification', UserPhoneVerification, basename='user-phone-verification')
|
router.register('user-phone-verification', UserPhoneVerification, basename='user-phone-verification')
|
||||||
router.register('user-email-verification', UserEmailVerification, basename='user-email-verification')
|
router.register('user-email-verification', UserEmailVerification, basename='user-email-verification')
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from django.core.mail import send_mail
|
"""Account utils"""
|
||||||
|
"""Third party Django app"""
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import random
|
|
||||||
from rest_framework import viewsets, status
|
from rest_framework import viewsets, status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
@@ -1,43 +1,62 @@
|
|||||||
from rest_framework import viewsets, status, views
|
from rest_framework import viewsets, status, views
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
import random
|
import random
|
||||||
|
import logging
|
||||||
from django.contrib.auth import authenticate, login
|
from django.contrib.auth import authenticate, login
|
||||||
from guardian.models import Guardian
|
from guardian.models import Guardian
|
||||||
from junior.models import Junior
|
from junior.models import Junior
|
||||||
from account.models import UserProfile, UserPhoneOtp, UserEmailOtp
|
from account.models import UserProfile, UserPhoneOtp, UserEmailOtp
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from .serializers import (SuperUserSerializer, GuardianSerializer, JuniorSerializer, EmailVerificationSerializer,
|
from .serializers import (SuperUserSerializer, GuardianSerializer, JuniorSerializer, EmailVerificationSerializer,
|
||||||
ForgotPasswordSerializer, ResetPasswordSerializer, ChangePasswordSerializer)
|
ForgotPasswordSerializer, ResetPasswordSerializer, ChangePasswordSerializer,
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
GoogleSignInSerializer)
|
||||||
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
|
||||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
|
||||||
from rest_framework_simplejwt.tokens import RefreshToken
|
from rest_framework_simplejwt.tokens import RefreshToken
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
from guardian.tasks import generate_otp
|
from guardian.tasks import generate_otp
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from account.utils import send_otp_email
|
||||||
from account.utils import custom_response, custom_error_response
|
from account.utils import custom_response, custom_error_response
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from templated_email import send_templated_mail
|
from templated_email import send_templated_mail
|
||||||
import secrets
|
|
||||||
|
# class GoogleLoginAPIViewset(viewsets.ModelViewSet):
|
||||||
|
# """Google Login"""
|
||||||
|
# serializer_class = GoogleSignInSerializer
|
||||||
|
#
|
||||||
|
# def create(self, request, *args, **kwargs):
|
||||||
|
# """
|
||||||
|
# Override default behaviour of create method
|
||||||
|
# """
|
||||||
|
# provider_type = []
|
||||||
|
# serializer = self.get_serializer(data=request.data)
|
||||||
|
# if serializer.is_valid(raise_exception=True):
|
||||||
|
# # provider = self.get_provider_view(request.data.get('provider'))
|
||||||
|
# # if User is not authenticated then send error message
|
||||||
|
# # if not provider.is_authenticated(request):
|
||||||
|
# # return custom_error_response({}, status.HTTP_400_BAD_REQUEST)
|
||||||
|
#
|
||||||
|
# user = serializer.save()
|
||||||
|
# if User.objects.filter(email__iexact=user.email).exists():
|
||||||
|
# print("ppppppppppppp")
|
||||||
|
# return custom_response(SUCCESS_CODE["3003"], response_status=status.HTTP_200_OK)
|
||||||
|
# return custom_response(ERROR_CODE["2002"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ChangePasswordAPIView(views.APIView):
|
class ChangePasswordAPIView(views.APIView):
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
print("request.data====>",request.data)
|
|
||||||
print("request.user====>", request.user)
|
|
||||||
serializer = ChangePasswordSerializer(context=request.user, data=request.data)
|
serializer = ChangePasswordSerializer(context=request.user, data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
return custom_response(SUCCESS_CODE['3006'], response_status=status.HTTP_200_OK)
|
return custom_response(SUCCESS_CODE['3007'], response_status=status.HTTP_200_OK)
|
||||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
class ResetPasswordAPIView(views.APIView):
|
class ResetPasswordAPIView(views.APIView):
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
print("request.data====>",request.data)
|
|
||||||
serializer = ResetPasswordSerializer(data=request.data)
|
serializer = ResetPasswordSerializer(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
@@ -65,8 +84,11 @@ class ForgotPasswordAPIView(views.APIView):
|
|||||||
'verification_code': verification_code
|
'verification_code': verification_code
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
UserEmailOtp.objects.create(email=email, otp=verification_code)
|
user_data, created = UserEmailOtp.objects.get_or_create(email=email)
|
||||||
return custom_response(SUCCESS_CODE['3015'], {'verification_code': verification_code},
|
if user_data:
|
||||||
|
user_data.otp = verification_code
|
||||||
|
user_data.save()
|
||||||
|
return custom_response(SUCCESS_CODE['3015'],
|
||||||
response_status=status.HTTP_200_OK)
|
response_status=status.HTTP_200_OK)
|
||||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
@@ -74,24 +96,30 @@ class SendPhoneOtp(viewsets.ModelViewSet):
|
|||||||
"""Send otp on phone"""
|
"""Send otp on phone"""
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
otp = generate_otp()
|
otp = generate_otp()
|
||||||
UserPhoneOtp.objects.create(country_code=self.request.data['country_code'],
|
phone_number = self.request.data['phone']
|
||||||
phone=self.request.data['phone'], otp=otp)
|
if phone_number.isdigit() and len(phone_number) == 10:
|
||||||
return custom_response(None, {'phone_otp':otp}, response_status=status.HTTP_200_OK)
|
phone_otp, created = UserPhoneOtp.objects.get_or_create(country_code=self.request.data['country_code'],
|
||||||
|
phone=self.request.data['phone'])
|
||||||
|
if phone_otp:
|
||||||
|
phone_otp.otp = otp
|
||||||
|
phone_otp.save()
|
||||||
|
return custom_response(None, {'phone_otp':otp}, response_status=status.HTTP_200_OK)
|
||||||
|
return custom_error_response(ERROR_CODE['2020'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
class UserPhoneVerification(viewsets.ModelViewSet):
|
class UserPhoneVerification(viewsets.ModelViewSet):
|
||||||
"""Send otp on phone"""
|
"""Send otp on phone"""
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
phone_data = UserPhoneOtp.objects.filter(phone=request.data['phone'],
|
phone_data = UserPhoneOtp.objects.filter(phone=self.request.GET.get('phone'),
|
||||||
otp=request.data['otp']).last()
|
otp=self.request.GET.get('otp')).last()
|
||||||
if phone_data:
|
if phone_data:
|
||||||
phone_data.is_verified = True
|
phone_data.is_verified = True
|
||||||
phone_data.save()
|
phone_data.save()
|
||||||
return custom_response(SUCCESS_CODE['3027'], response_status=status.HTTP_200_OK)
|
return custom_response(SUCCESS_CODE['3012'], response_status=status.HTTP_200_OK)
|
||||||
else:
|
else:
|
||||||
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
@@ -111,12 +139,11 @@ class UserLogin(viewsets.ViewSet):
|
|||||||
junior_data = Junior.objects.filter(auth__username=username, is_complete_profile=True).last()
|
junior_data = Junior.objects.filter(auth__username=username, is_complete_profile=True).last()
|
||||||
if junior_data:
|
if junior_data:
|
||||||
serializer = JuniorSerializer(junior_data)
|
serializer = JuniorSerializer(junior_data)
|
||||||
if user.is_superuser:
|
|
||||||
serializer = SuperUserSerializer(user)
|
|
||||||
return custom_response(SUCCESS_CODE['3003'], serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(SUCCESS_CODE['3003'], serializer.data, response_status=status.HTTP_200_OK)
|
||||||
else:
|
else:
|
||||||
return custom_error_response(ERROR_CODE["2002"], response_status=status.HTTP_401_UNAUTHORIZED)
|
return custom_error_response(ERROR_CODE["2002"], response_status=status.HTTP_401_UNAUTHORIZED)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
user_profile_data = UserProfile.objects.filter(user__username=username).last()
|
user_profile_data = UserProfile.objects.filter(user__username=username).last()
|
||||||
email_verified = UserEmailOtp.objects.filter(email=username).last()
|
email_verified = UserEmailOtp.objects.filter(email=username).last()
|
||||||
refresh = RefreshToken.for_user(user)
|
refresh = RefreshToken.for_user(user)
|
||||||
@@ -132,26 +159,50 @@ class UserLogin(viewsets.ViewSet):
|
|||||||
email_verified.otp = otp
|
email_verified.otp = otp
|
||||||
email_verified.save()
|
email_verified.save()
|
||||||
data.update({"email_otp":otp})
|
data.update({"email_otp":otp})
|
||||||
return custom_response(ERROR_CODE['2024'], {"email_otp":otp, "is_email_verified": is_verified},
|
return custom_response(ERROR_CODE['2024'], {"email_otp": otp, "is_email_verified": is_verified},
|
||||||
response_status=status.HTTP_400_BAD_REQUEST)
|
response_status=status.HTTP_200_OK)
|
||||||
data.update({"is_email_verified": is_verified})
|
data.update({"is_email_verified": is_verified})
|
||||||
return custom_response(None, data, response_status=status.HTTP_200_OK)
|
return custom_response(None, data, response_status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=False)
|
||||||
|
def admin_login(self, request):
|
||||||
|
username = request.data.get('username')
|
||||||
|
password = request.data.get('password')
|
||||||
|
user = authenticate(request, username=username, password=password)
|
||||||
|
try:
|
||||||
|
if user is not None:
|
||||||
|
login(request, user)
|
||||||
|
if user.is_superuser:
|
||||||
|
serializer = SuperUserSerializer(user)
|
||||||
|
return custom_response(SUCCESS_CODE['3003'], serializer.data, response_status=status.HTTP_200_OK)
|
||||||
|
else:
|
||||||
|
return custom_error_response(ERROR_CODE["2002"], response_status=status.HTTP_401_UNAUTHORIZED)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
|
refresh = RefreshToken.for_user(user)
|
||||||
|
access_token = str(refresh.access_token)
|
||||||
|
data = {"auth_token": access_token, "user_role": '3'}
|
||||||
|
return custom_response(None, data, response_status=status.HTTP_200_OK)
|
||||||
|
|
||||||
class UserEmailVerification(viewsets.ModelViewSet):
|
class UserEmailVerification(viewsets.ModelViewSet):
|
||||||
"""User Email verification"""
|
"""User Email verification"""
|
||||||
serializer_class = EmailVerificationSerializer
|
serializer_class = EmailVerificationSerializer
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
email_data = UserEmailOtp.objects.filter(email=request.data['email'],
|
user_obj = User.objects.filter(username=self.request.GET.get('email')).last()
|
||||||
otp=request.data['otp']).last()
|
email_data = UserEmailOtp.objects.filter(email=self.request.GET.get('email'),
|
||||||
|
otp=self.request.GET.get('otp')).last()
|
||||||
if email_data:
|
if email_data:
|
||||||
email_data.is_verified = True
|
email_data.is_verified = True
|
||||||
email_data.save()
|
email_data.save()
|
||||||
return custom_response(SUCCESS_CODE['3011'], response_status=status.HTTP_200_OK)
|
refresh = RefreshToken.for_user(user_obj)
|
||||||
|
access_token = str(refresh.access_token)
|
||||||
|
return custom_response(SUCCESS_CODE['3011'], {"auth_token":access_token}, response_status=status.HTTP_200_OK)
|
||||||
else:
|
else:
|
||||||
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logging.error(e)
|
||||||
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
class ReSendEmailOtp(viewsets.ModelViewSet):
|
class ReSendEmailOtp(viewsets.ModelViewSet):
|
||||||
@@ -159,8 +210,11 @@ class ReSendEmailOtp(viewsets.ModelViewSet):
|
|||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
otp = generate_otp()
|
otp = generate_otp()
|
||||||
if User.objects.filter(email=request.data['email']):
|
if User.objects.filter(email=request.data['email']):
|
||||||
UserEmailOtp.objects.create(email=request.data['email'], otp=otp)
|
email_data, created = UserEmailOtp.objects.get_or_create(email=request.data['email'])
|
||||||
return custom_response(None, {'email_otp': otp}, response_status=status.HTTP_200_OK)
|
if email_data:
|
||||||
|
email_data.otp = otp
|
||||||
|
email_data.save()
|
||||||
|
send_otp_email(request.data['email'], otp)
|
||||||
|
return custom_response(SUCCESS_CODE['3016'], response_status=status.HTTP_200_OK)
|
||||||
else:
|
else:
|
||||||
return custom_error_response(ERROR_CODE["2023"], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE["2023"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
@@ -14,8 +14,7 @@ SUPER_ADMIN = "Super Admin"
|
|||||||
JWT_TOKEN_EXPIRATION = 3 * 24 * 60
|
JWT_TOKEN_EXPIRATION = 3 * 24 * 60
|
||||||
|
|
||||||
# Define common file extention
|
# Define common file extention
|
||||||
FILE_EXTENSION = ("gif", "jpeg", "jpg", "png", "svg", "csv", "doc", "docx", "odt", "pdf", "rtf", "txt", "wks", "wp",
|
FILE_EXTENSION = ("gif", "jpeg", "jpg", "png", "svg")
|
||||||
"wpd")
|
|
||||||
|
|
||||||
# Define file size in bytes(5MB = 5 * 1024 * 1024)
|
# Define file size in bytes(5MB = 5 * 1024 * 1024)
|
||||||
FILE_SIZE = 5 * 1024 * 1024
|
FILE_SIZE = 5 * 1024 * 1024
|
||||||
@@ -42,53 +41,6 @@ GUARDIAN = 'guardian'
|
|||||||
JUNIOR = 'junior'
|
JUNIOR = 'junior'
|
||||||
SUPERUSER = 'superuser'
|
SUPERUSER = 'superuser'
|
||||||
# numbers used as a constant
|
# numbers used as a constant
|
||||||
NUMBER = {
|
|
||||||
'point_zero': 0.0,
|
|
||||||
'zero': 0,
|
|
||||||
'one': 1,
|
|
||||||
'two': 2,
|
|
||||||
'three': 3,
|
|
||||||
'four': 4,
|
|
||||||
'five': 5,
|
|
||||||
'six': 6,
|
|
||||||
'seven': 7,
|
|
||||||
'eight': 8,
|
|
||||||
'nine': 9,
|
|
||||||
'ten': 10,
|
|
||||||
'eleven': 11,
|
|
||||||
'twelve': 12,
|
|
||||||
'thirteen': 13,
|
|
||||||
'fourteen': 14,
|
|
||||||
'fifteen': 15,
|
|
||||||
'sixteen': 16,
|
|
||||||
'seventeen': 17,
|
|
||||||
'eighteen': 18,
|
|
||||||
'nineteen': 19,
|
|
||||||
'twenty_four': 24,
|
|
||||||
'twenty_one': 21,
|
|
||||||
'twenty_two': 22,
|
|
||||||
'twenty_five': 25,
|
|
||||||
'thirty': 30,
|
|
||||||
'thirty_five': 35,
|
|
||||||
'thirty_six': 36,
|
|
||||||
'forty': 40,
|
|
||||||
'fifty': 50,
|
|
||||||
'fifty_nine': 59,
|
|
||||||
'sixty': 60,
|
|
||||||
'seventy_five': 75,
|
|
||||||
'eighty': 80,
|
|
||||||
'ninty_five': 95,
|
|
||||||
'ninty_six': 96,
|
|
||||||
'ninety_nine': 99,
|
|
||||||
'hundred': 100,
|
|
||||||
'one_one_nine': 119,
|
|
||||||
'one_twenty': 120,
|
|
||||||
'four_zero_four': 404,
|
|
||||||
'five_hundred': 500,
|
|
||||||
'minus_one': -1,
|
|
||||||
'point_three': 0.3,
|
|
||||||
'point_seven': 0.7
|
|
||||||
}
|
|
||||||
|
|
||||||
# Define the byte into kb
|
# Define the byte into kb
|
||||||
BYTE_IMAGE_SIZE = 1024
|
BYTE_IMAGE_SIZE = 1024
|
||||||
@@ -63,7 +63,7 @@ SUCCESS_CODE = {
|
|||||||
# Success code for password reset
|
# Success code for password reset
|
||||||
"3006": "Your password has been reset successfully.",
|
"3006": "Your password has been reset successfully.",
|
||||||
# Success code for password update
|
# Success code for password update
|
||||||
"3007": "Your password has been updated successfully.",
|
"3007": "Your password has been changed successfully.",
|
||||||
# Success code for valid link
|
# Success code for valid link
|
||||||
"3008": "You have a valid link.",
|
"3008": "You have a valid link.",
|
||||||
# Success code for logged out
|
# Success code for logged out
|
||||||
@@ -74,7 +74,8 @@ SUCCESS_CODE = {
|
|||||||
"3012": "Phone OTP Verified successfully",
|
"3012": "Phone OTP Verified successfully",
|
||||||
"3013": "Valid Guardian code",
|
"3013": "Valid Guardian code",
|
||||||
"3014": "Password has been updated successfully.",
|
"3014": "Password has been updated successfully.",
|
||||||
"3015": "Verification code sent on your email."
|
"3015": "Verification code sent on your email.",
|
||||||
|
"3016": "Send otp on your Email successfully"
|
||||||
}
|
}
|
||||||
|
|
||||||
STATUS_CODE_ERROR = {
|
STATUS_CODE_ERROR = {
|
||||||
@@ -16,8 +16,8 @@ from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_200_OK
|
|||||||
from base import constants
|
from base import constants
|
||||||
from base.constants import NUMBER
|
from base.constants import NUMBER
|
||||||
# local import
|
# local import
|
||||||
from resourcekit.settings import base_settings as settings
|
from zod_bank.settings import base_settings as settings
|
||||||
from resourcekit.settings.base_settings import BASE_DIR
|
from zod_bank.settings.base_settings import BASE_DIR
|
||||||
|
|
||||||
|
|
||||||
def image_upload(folder, file_name, data):
|
def image_upload(folder, file_name, data):
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
nginx:
|
||||||
|
image: nginx:latest
|
||||||
|
container_name: nginx
|
||||||
|
ports:
|
||||||
|
- "8000:8000"
|
||||||
|
volumes:
|
||||||
|
- ./nginx:/etc/nginx/conf.d
|
||||||
|
- .:/usr/src/app
|
||||||
|
depends_on:
|
||||||
|
- web
|
||||||
|
web:
|
||||||
|
build: .
|
||||||
|
container_name: django
|
||||||
|
command: bash -c "pip install -r requirements.txt && python manage.py collectstatic --noinput && python manage.py migrate && gunicorn zod_bank.wsgi -b 0.0.0.0:8000 -t 300 --log-level=info"
|
||||||
|
volumes:
|
||||||
|
- .:/usr/src/app
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
|
"""Guardian admin"""
|
||||||
|
"""Third party Django app"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
"""Import Django app"""
|
||||||
from .models import Guardian
|
from .models import Guardian
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
@admin.register(Guardian)
|
@admin.register(Guardian)
|
||||||
class GuardianAdmin(admin.ModelAdmin):
|
class GuardianAdmin(admin.ModelAdmin):
|
||||||
|
"""Junior Admin"""
|
||||||
list_display = ['user', 'family_name']
|
list_display = ['user', 'family_name']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.user__email
|
"""Return email id"""
|
||||||
|
return self.user__email
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
|
"""Guardian app file"""
|
||||||
|
"""Third party Django app"""
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class CustodianConfig(AppConfig):
|
class CustodianConfig(AppConfig):
|
||||||
|
"""Guardian config"""
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'guardian'
|
name = 'guardian'
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-06-27 06:15
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('guardian', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='guardian',
|
||||||
|
name='junior_code',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-06-27 13:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('guardian', '0002_remove_guardian_junior_code'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='guardian',
|
||||||
|
name='country_name',
|
||||||
|
field=models.CharField(blank=True, default=None, max_length=30, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,24 +1,32 @@
|
|||||||
|
"""Guardian model file"""
|
||||||
|
"""Third party Django app"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
"""Import Django app"""
|
||||||
from base.constants import GENDERS
|
from base.constants import GENDERS
|
||||||
from django.contrib.postgres.fields import ArrayField
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
class Guardian(models.Model):
|
class Guardian(models.Model):
|
||||||
|
"""Guardian model"""
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='guardian_profile', verbose_name='Email')
|
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='guardian_profile', verbose_name='Email')
|
||||||
|
"""Contact details"""
|
||||||
country_code = models.IntegerField(blank=True, null=True)
|
country_code = models.IntegerField(blank=True, null=True)
|
||||||
phone = models.CharField(max_length=31, null=True, blank=True, default=None)
|
phone = models.CharField(max_length=31, null=True, blank=True, default=None)
|
||||||
|
country_name = models.CharField(max_length=30, null=True, blank=True, default=None)
|
||||||
|
"""Personal info"""
|
||||||
family_name = models.CharField(max_length=50, null=True, blank=True, default=None)
|
family_name = models.CharField(max_length=50, null=True, blank=True, default=None)
|
||||||
gender = models.CharField(choices=GENDERS, max_length=15, null=True, blank=True, default=None)
|
gender = models.CharField(choices=GENDERS, max_length=15, null=True, blank=True, default=None)
|
||||||
dob = models.DateField(max_length=15, null=True, blank=True, default=None)
|
dob = models.DateField(max_length=15, null=True, blank=True, default=None)
|
||||||
|
"""Codes"""
|
||||||
guardian_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
guardian_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||||
junior_code = ArrayField(models.CharField(max_length=10, null=True, blank=True, default=None),null=True)
|
|
||||||
referral_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
referral_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||||
referral_code_used = models.CharField(max_length=10, null=True, blank=True, default=None)
|
referral_code_used = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||||
|
"""Profile activity"""
|
||||||
is_active = models.BooleanField(default=True)
|
is_active = models.BooleanField(default=True)
|
||||||
is_complete_profile = models.BooleanField(default=False)
|
is_complete_profile = models.BooleanField(default=False)
|
||||||
passcode = models.IntegerField(null=True, blank=True, default=None)
|
passcode = models.IntegerField(null=True, blank=True, default=None)
|
||||||
|
"""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)
|
||||||
|
|
||||||
@@ -28,4 +36,5 @@ class Guardian(models.Model):
|
|||||||
verbose_name = 'Guardian'
|
verbose_name = 'Guardian'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
"""Return email id"""
|
||||||
return f'{self.user}'
|
return f'{self.user}'
|
||||||
@@ -1,91 +1,117 @@
|
|||||||
from rest_framework import serializers
|
"""Serializer of Guardian"""
|
||||||
from django.contrib.auth.models import User
|
"""Third party Django app"""
|
||||||
from .models import Guardian
|
import logging
|
||||||
from django.db import transaction
|
|
||||||
import random
|
import random
|
||||||
from account.models import UserProfile
|
from rest_framework import serializers
|
||||||
from junior.models import Junior
|
|
||||||
from base.constants import GENDERS, GUARDIAN, JUNIOR, SUPERUSER
|
|
||||||
from rest_framework_simplejwt.tokens import RefreshToken
|
from rest_framework_simplejwt.tokens import RefreshToken
|
||||||
|
from django.db import transaction
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
"""Import Django app"""
|
||||||
|
from .models import Guardian
|
||||||
|
from account.models import UserProfile
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
class UserSerializer(serializers.ModelSerializer):
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
|
"""User serializer"""
|
||||||
auth_token = serializers.SerializerMethodField('get_auth_token')
|
auth_token = serializers.SerializerMethodField('get_auth_token')
|
||||||
|
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
|
"""Meta info"""
|
||||||
model = User
|
model = User
|
||||||
fields = ['email', 'password', 'auth_token']
|
fields = ['email', 'password', 'auth_token']
|
||||||
|
|
||||||
def get_auth_token(self, obj):
|
def get_auth_token(self, obj):
|
||||||
|
"""generate auth token"""
|
||||||
refresh = RefreshToken.for_user(obj)
|
refresh = RefreshToken.for_user(obj)
|
||||||
access_token = str(refresh.access_token)
|
access_token = str(refresh.access_token)
|
||||||
return access_token
|
return access_token
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
"""fetch data"""
|
||||||
email = validated_data.get('email')
|
email = validated_data.get('email')
|
||||||
user_type = self.context
|
user_type = self.context
|
||||||
password = validated_data.get('password')
|
password = validated_data.get('password')
|
||||||
try:
|
try:
|
||||||
|
"""Create user profile"""
|
||||||
user = User.objects.create_user(username=email, email=email, password=password)
|
user = User.objects.create_user(username=email, email=email, password=password)
|
||||||
UserProfile.objects.create(user=user, user_type=user_type)
|
UserProfile.objects.create(user=user, user_type=user_type)
|
||||||
return user
|
return user
|
||||||
except:
|
except Exception as e:
|
||||||
|
"""Error handling"""
|
||||||
|
logging.error(e)
|
||||||
raise serializers.ValidationError({"details":ERROR_CODE['2021']})
|
raise serializers.ValidationError({"details":ERROR_CODE['2021']})
|
||||||
|
|
||||||
def save(self, **kwargs):
|
def save(self, **kwargs):
|
||||||
|
"""save the data"""
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
instance = super().save(**kwargs)
|
instance = super().save(**kwargs)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
class CreateGuardianSerializer(serializers.ModelSerializer):
|
class CreateGuardianSerializer(serializers.ModelSerializer):
|
||||||
|
"""Create guardian serializer"""
|
||||||
|
"""Basic info"""
|
||||||
first_name = serializers.SerializerMethodField('get_first_name')
|
first_name = serializers.SerializerMethodField('get_first_name')
|
||||||
last_name = serializers.SerializerMethodField('get_last_name')
|
last_name = serializers.SerializerMethodField('get_last_name')
|
||||||
email = serializers.SerializerMethodField('get_email')
|
email = serializers.SerializerMethodField('get_email')
|
||||||
|
"""Contact details"""
|
||||||
phone = serializers.CharField(max_length=20, required=False)
|
phone = serializers.CharField(max_length=20, required=False)
|
||||||
family_name = serializers.CharField(max_length=100, required=False)
|
|
||||||
country_code = serializers.IntegerField(required=False)
|
country_code = serializers.IntegerField(required=False)
|
||||||
|
family_name = serializers.CharField(max_length=100, required=False)
|
||||||
dob = serializers.DateField(required=False)
|
dob = serializers.DateField(required=False)
|
||||||
referral_code = serializers.CharField(max_length=100, required=False)
|
referral_code = serializers.CharField(max_length=100, required=False)
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
|
"""Meta info"""
|
||||||
model = Guardian
|
model = Guardian
|
||||||
fields = ['first_name', 'last_name', 'email', 'phone', 'family_name', 'gender', 'country_code', 'dob', 'referral_code', 'passcode',
|
fields = ['first_name', 'last_name', 'email', 'phone', 'family_name', 'gender', 'country_code',
|
||||||
'is_complete_profile']
|
'dob', 'referral_code', 'passcode', 'is_complete_profile']
|
||||||
|
|
||||||
def get_first_name(self,obj):
|
def get_first_name(self,obj):
|
||||||
|
"""first name of guardian"""
|
||||||
return obj.user.first_name
|
return obj.user.first_name
|
||||||
|
|
||||||
def get_last_name(self,obj):
|
def get_last_name(self,obj):
|
||||||
|
"""last name of guardian"""
|
||||||
return obj.user.last_name
|
return obj.user.last_name
|
||||||
|
|
||||||
def get_email(self,obj):
|
def get_email(self,obj):
|
||||||
|
"""emailof guardian"""
|
||||||
return obj.user.email
|
return obj.user.email
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
"""Create guardian profile"""
|
||||||
user = User.objects.filter(username=self.context['user']).last()
|
user = User.objects.filter(username=self.context['user']).last()
|
||||||
if user:
|
if user:
|
||||||
|
"""Save first and last name of guardian"""
|
||||||
user.first_name = self.context.get('first_name', user.first_name)
|
user.first_name = self.context.get('first_name', user.first_name)
|
||||||
user.last_name = self.context.get('last_name', user.last_name)
|
user.last_name = self.context.get('last_name', user.last_name)
|
||||||
user.save()
|
user.save()
|
||||||
|
"""Create guardian data"""
|
||||||
guardian, created = Guardian.objects.get_or_create(user=self.context['user'])
|
guardian, created = Guardian.objects.get_or_create(user=self.context['user'])
|
||||||
if created:
|
if created:
|
||||||
|
"""Create referral code and guardian code"""
|
||||||
guardian.referral_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
guardian.referral_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
||||||
guardian.guardian_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
guardian.guardian_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
||||||
if guardian:
|
if guardian:
|
||||||
guardian.phone = validated_data.get('phone', guardian.phone)
|
"""update details according to the data get from request"""
|
||||||
guardian.gender = validated_data.get('gender',guardian.gender)
|
guardian.gender = validated_data.get('gender',guardian.gender)
|
||||||
guardian.family_name = validated_data.get('family_name', guardian.family_name)
|
guardian.family_name = validated_data.get('family_name', guardian.family_name)
|
||||||
guardian.dob = validated_data.get('dob',guardian.dob)
|
guardian.dob = validated_data.get('dob',guardian.dob)
|
||||||
|
"""Update country code and phone number"""
|
||||||
|
guardian.phone = validated_data.get('phone', guardian.phone)
|
||||||
|
guardian.country_code = validated_data.get('country_code', guardian.country_code)
|
||||||
guardian.passcode = validated_data.get('passcode', guardian.passcode)
|
guardian.passcode = validated_data.get('passcode', guardian.passcode)
|
||||||
|
guardian.country_name = validated_data.get('country_name', guardian.country_name)
|
||||||
|
guardian.referral_code_used = validated_data.get('referral_code_used', guardian.referral_code_used)
|
||||||
|
"""Complete profile of the junior if below all data are filled"""
|
||||||
complete_profile_field = all([guardian.phone, guardian.gender, guardian.family_name,
|
complete_profile_field = all([guardian.phone, guardian.gender, guardian.family_name,
|
||||||
guardian.dob, guardian.country_code, user.first_name, user.last_name])
|
guardian.dob, guardian.country_code, user.first_name, user.last_name])
|
||||||
guardian.is_complete_profile = False
|
guardian.is_complete_profile = False
|
||||||
if complete_profile_field:
|
if complete_profile_field:
|
||||||
guardian.is_complete_profile = True
|
guardian.is_complete_profile = True
|
||||||
guardian.country_code = validated_data.get('country_code', guardian.country_code)
|
|
||||||
guardian.save()
|
guardian.save()
|
||||||
return guardian
|
return guardian
|
||||||
|
|
||||||
def save(self, **kwargs):
|
def save(self, **kwargs):
|
||||||
|
"""Save the data into junior table"""
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
instance = super().save(**kwargs)
|
instance = super().save(**kwargs)
|
||||||
return instance
|
return instance
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"""Test file of Guardian"""
|
||||||
|
"""Third party Django app"""
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
""" Urls files"""
|
""" Urls files"""
|
||||||
"""Django import"""
|
"""Django import"""
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from rest_framework.decorators import api_view
|
|
||||||
from .views import SignupViewset, UpdateGuardianProfile
|
from .views import SignupViewset, UpdateGuardianProfile
|
||||||
"""Third party import"""
|
"""Third party import"""
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
|
|
||||||
"""Router"""
|
"""Define Router"""
|
||||||
router = routers.SimpleRouter()
|
router = routers.SimpleRouter()
|
||||||
|
|
||||||
"""API End points with router"""
|
"""API End points with router"""
|
||||||
|
"""Sign up API"""
|
||||||
router.register('sign-up', SignupViewset, basename='sign-up')
|
router.register('sign-up', SignupViewset, basename='sign-up')
|
||||||
router.register('complete-guardian-profile', UpdateGuardianProfile, basename='update-guardian-profile')
|
"""Create guardian profile API"""
|
||||||
|
router.register('create-guardian-profile', UpdateGuardianProfile, basename='update-guardian-profile')
|
||||||
|
"""Define Url pattern"""
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api/v1/', include(router.urls)),
|
path('api/v1/', include(router.urls)),
|
||||||
]
|
]
|
||||||
@@ -1,45 +1,47 @@
|
|||||||
from django.shortcuts import render
|
"""Views of Guardian"""
|
||||||
from rest_framework import (pagination, viewsets, status, generics, mixins)
|
"""Third party Django app"""
|
||||||
from .serializers import CreateGuardianSerializer
|
|
||||||
from rest_framework.decorators import action
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
|
||||||
# Create your views here.
|
|
||||||
from rest_framework import viewsets, status
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from .serializers import UserSerializer
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from base.constants import GUARDIAN, JUNIOR, SUPERUSER
|
from rest_framework import viewsets, status
|
||||||
from junior.models import Junior
|
"""Import Django app"""
|
||||||
|
from .serializers import UserSerializer
|
||||||
|
from .serializers import CreateGuardianSerializer
|
||||||
from account.models import UserEmailOtp
|
from account.models import UserEmailOtp
|
||||||
from .tasks import generate_otp
|
from .tasks import generate_otp
|
||||||
from account.utils import send_otp_email
|
from account.utils import send_otp_email
|
||||||
from account.utils import custom_response, custom_error_response
|
from account.utils import custom_response, custom_error_response
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
|
# Create your views here.
|
||||||
class SignupViewset(viewsets.ModelViewSet):
|
class SignupViewset(viewsets.ModelViewSet):
|
||||||
|
"""Signup view set"""
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
|
"""Create user profile"""
|
||||||
serializer = UserSerializer(context=request.data['user_type'], data=request.data)
|
serializer = UserSerializer(context=request.data['user_type'], data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
|
"""Generate otp"""
|
||||||
otp = generate_otp()
|
otp = generate_otp()
|
||||||
UserEmailOtp.objects.create(email=request.data['email'], otp=otp)
|
UserEmailOtp.objects.create(email=request.data['email'], otp=otp)
|
||||||
|
"""Send email to the register user"""
|
||||||
send_otp_email(request.data['email'], otp)
|
send_otp_email(request.data['email'], otp)
|
||||||
return custom_response(SUCCESS_CODE['3001'], {"email_otp": otp},
|
return custom_response(SUCCESS_CODE['3001'], {"email_otp": otp},
|
||||||
response_status=status.HTTP_200_OK)
|
response_status=status.HTTP_200_OK)
|
||||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
class UpdateGuardianProfile(viewsets.ViewSet):
|
class UpdateGuardianProfile(viewsets.ViewSet):
|
||||||
|
"""Update guardian profile"""
|
||||||
serializer_class = CreateGuardianSerializer
|
serializer_class = CreateGuardianSerializer
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
serializer = CreateGuardianSerializer(context={"user":request.user,"first_name":request.data.get('first_name', ''),
|
"""Create guardian profile"""
|
||||||
"last_name": request.data.get('last_name',' ')}, data=request.data)
|
serializer = CreateGuardianSerializer(context={"user":request.user,
|
||||||
|
"first_name":request.data.get('first_name', ''),
|
||||||
|
"last_name": request.data.get('last_name',' ')},
|
||||||
|
data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
|
"""save serializer"""
|
||||||
serializer.save()
|
serializer.save()
|
||||||
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_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
|
"""Junior admin"""
|
||||||
|
"""Third party Django app"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
"""Import Django app"""
|
||||||
from .models import Junior
|
from .models import Junior
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
@admin.register(Junior)
|
@admin.register(Junior)
|
||||||
class JuniorAdmin(admin.ModelAdmin):
|
class JuniorAdmin(admin.ModelAdmin):
|
||||||
|
"""Junior Admin"""
|
||||||
list_display = ['auth']
|
list_display = ['auth']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
"""Return email id"""
|
||||||
return self.auth__email
|
return self.auth__email
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
"""App file"""
|
||||||
|
"""Import AppConfig"""
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
class JuniorConfig(AppConfig):
|
class JuniorConfig(AppConfig):
|
||||||
|
"""Junior config"""
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'junior'
|
name = 'junior'
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-06-27 13:59
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('junior', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='junior',
|
||||||
|
name='country_name',
|
||||||
|
field=models.CharField(blank=True, default=None, max_length=30, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,25 +1,34 @@
|
|||||||
|
"""Junior model """
|
||||||
|
"""Import django"""
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from base.constants import GENDERS
|
|
||||||
from guardian.models import Guardian
|
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
|
"""Import django app"""
|
||||||
|
from base.constants import GENDERS
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
class Junior(models.Model):
|
class Junior(models.Model):
|
||||||
|
"""Junior model"""
|
||||||
auth = models.ForeignKey(User, on_delete=models.CASCADE, related_name='junior_profile', verbose_name='Email')
|
auth = models.ForeignKey(User, on_delete=models.CASCADE, related_name='junior_profile', verbose_name='Email')
|
||||||
|
"""Contact details"""
|
||||||
phone = models.CharField(max_length=31, null=True, blank=True, default=None)
|
phone = models.CharField(max_length=31, null=True, blank=True, default=None)
|
||||||
country_code = models.IntegerField(blank=True, null=True)
|
country_code = models.IntegerField(blank=True, null=True)
|
||||||
|
country_name = models.CharField(max_length=30, null=True, blank=True, default=None)
|
||||||
|
"""Personal info"""
|
||||||
gender = models.CharField(max_length=10, choices=GENDERS, null=True, blank=True, default=None)
|
gender = models.CharField(max_length=10, choices=GENDERS, null=True, blank=True, default=None)
|
||||||
dob = models.DateField(max_length=15, null=True, blank=True, default=None)
|
dob = models.DateField(max_length=15, null=True, blank=True, default=None)
|
||||||
# image = models.ImageField(upload_to='images/')
|
# image = models.ImageField(upload_to='images/')
|
||||||
|
"""Codes"""
|
||||||
junior_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
junior_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||||
guardian_code = ArrayField(models.CharField(max_length=10, null=True, blank=True, default=None),null=True)
|
guardian_code = ArrayField(models.CharField(max_length=10, null=True, blank=True, default=None),null=True)
|
||||||
referral_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
referral_code = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||||
referral_code_used = models.CharField(max_length=10, null=True, blank=True, default=None)
|
referral_code_used = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||||
|
"""Profile activity"""
|
||||||
is_active = models.BooleanField(default=True)
|
is_active = models.BooleanField(default=True)
|
||||||
is_complete_profile = models.BooleanField(default=False)
|
is_complete_profile = models.BooleanField(default=False)
|
||||||
passcode = models.IntegerField(null=True, blank=True, default=None)
|
passcode = models.IntegerField(null=True, blank=True, default=None)
|
||||||
|
"""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)
|
||||||
|
|
||||||
@@ -29,4 +38,5 @@ class Junior(models.Model):
|
|||||||
verbose_name = 'Junior'
|
verbose_name = 'Junior'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
"""Return email id"""
|
||||||
return f'{self.auth}'
|
return f'{self.auth}'
|
||||||
@@ -1,28 +1,29 @@
|
|||||||
|
"""Serializer file for junior"""
|
||||||
|
"""Import Django 3rd party app"""
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from .models import Guardian
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
import random
|
import random
|
||||||
from account.models import UserProfile
|
"""Import django app"""
|
||||||
from junior.models import Junior
|
from junior.models import Junior
|
||||||
from base.constants import GENDERS, GUARDIAN, JUNIOR, SUPERUSER
|
|
||||||
from rest_framework_simplejwt.tokens import RefreshToken
|
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
|
||||||
from django.contrib.postgres.fields import ArrayField
|
|
||||||
|
|
||||||
class ListCharField(serializers.ListField):
|
class ListCharField(serializers.ListField):
|
||||||
|
"""Serializer for Array field"""
|
||||||
child = serializers.CharField()
|
child = serializers.CharField()
|
||||||
|
|
||||||
def to_representation(self, data):
|
def to_representation(self, data):
|
||||||
|
"""to represent the data"""
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
|
"""internal value"""
|
||||||
if isinstance(data, list):
|
if isinstance(data, list):
|
||||||
return data
|
return data
|
||||||
raise serializers.ValidationError({"details":"Invalid input. Expected a list of strings."})
|
raise serializers.ValidationError({"details":"Invalid input. Expected a list of strings."})
|
||||||
|
|
||||||
|
|
||||||
class CreateJuniorSerializer(serializers.ModelSerializer):
|
class CreateJuniorSerializer(serializers.ModelSerializer):
|
||||||
|
"""Create junior serializer"""
|
||||||
first_name = serializers.SerializerMethodField('get_first_name')
|
first_name = serializers.SerializerMethodField('get_first_name')
|
||||||
last_name = serializers.SerializerMethodField('get_last_name')
|
last_name = serializers.SerializerMethodField('get_last_name')
|
||||||
email = serializers.SerializerMethodField('get_email')
|
email = serializers.SerializerMethodField('get_email')
|
||||||
@@ -33,41 +34,60 @@ class CreateJuniorSerializer(serializers.ModelSerializer):
|
|||||||
guardian_code = ListCharField(required=False)
|
guardian_code = ListCharField(required=False)
|
||||||
|
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
|
"""Meta info"""
|
||||||
model = Junior
|
model = Junior
|
||||||
fields = ['first_name', 'last_name', 'email', 'phone', 'gender', 'country_code', 'dob', 'referral_code',
|
fields = ['first_name', 'last_name', 'email', 'phone', 'gender', 'country_code', 'dob', 'referral_code',
|
||||||
'passcode', 'is_complete_profile', 'guardian_code']
|
'passcode', 'is_complete_profile', 'guardian_code']
|
||||||
|
|
||||||
def get_first_name(self,obj):
|
def get_first_name(self,obj):
|
||||||
|
"""first name of junior"""
|
||||||
return obj.auth.first_name
|
return obj.auth.first_name
|
||||||
|
|
||||||
def get_last_name(self,obj):
|
def get_last_name(self,obj):
|
||||||
|
"""last name of junior"""
|
||||||
return obj.auth.last_name
|
return obj.auth.last_name
|
||||||
|
|
||||||
def get_email(self,obj):
|
def get_email(self,obj):
|
||||||
|
"""email of junior"""
|
||||||
return obj.auth.email
|
return obj.auth.email
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
"""Create junior profile"""
|
||||||
user = User.objects.filter(username=self.context['user']).last()
|
user = User.objects.filter(username=self.context['user']).last()
|
||||||
if user:
|
if user:
|
||||||
|
"""Save first and last name of junior"""
|
||||||
user.first_name = self.context.get('first_name', user.first_name)
|
user.first_name = self.context.get('first_name', user.first_name)
|
||||||
user.last_name = self.context.get('last_name', user.last_name)
|
user.last_name = self.context.get('last_name', user.last_name)
|
||||||
user.save()
|
user.save()
|
||||||
|
"""Create junior data"""
|
||||||
junior, created = Junior.objects.get_or_create(auth=self.context['user'])
|
junior, created = Junior.objects.get_or_create(auth=self.context['user'])
|
||||||
if created:
|
if created:
|
||||||
|
"""Create referral code and junior code"""
|
||||||
junior.referral_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
junior.referral_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
||||||
junior.junior_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
junior.junior_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
||||||
if junior:
|
if junior:
|
||||||
junior.phone = validated_data.get('phone', junior.phone)
|
"""update details according to the data get from request"""
|
||||||
junior.gender = validated_data.get('gender',junior.gender)
|
junior.gender = validated_data.get('gender',junior.gender)
|
||||||
|
"""Update guardian code"""
|
||||||
junior.guardian_code = validated_data.get('guardian_code', junior.guardian_code)
|
junior.guardian_code = validated_data.get('guardian_code', junior.guardian_code)
|
||||||
junior.dob = validated_data.get('dob',junior.dob)
|
junior.dob = validated_data.get('dob',junior.dob)
|
||||||
junior.passcode = validated_data.get('passcode', junior.passcode)
|
junior.passcode = validated_data.get('passcode', junior.passcode)
|
||||||
junior.is_complete_profile = validated_data.get('is_complete_profile', junior.is_complete_profile)
|
junior.country_name = validated_data.get('country_name', junior.country_name)
|
||||||
|
"""Update country code and phone number"""
|
||||||
|
junior.phone = validated_data.get('phone', junior.phone)
|
||||||
junior.country_code = validated_data.get('country_code', junior.country_code)
|
junior.country_code = validated_data.get('country_code', junior.country_code)
|
||||||
|
junior.referral_code_used = validated_data.get('referral_code_used', junior.referral_code_used)
|
||||||
|
"""Complete profile of the junior if below all data are filled"""
|
||||||
|
complete_profile_field = all([junior.phone, junior.gender, junior.family_name,
|
||||||
|
junior.dob, junior.country_code, user.first_name, user.last_name])
|
||||||
|
junior.is_complete_profile = False
|
||||||
|
if complete_profile_field:
|
||||||
|
junior.is_complete_profile = True
|
||||||
junior.save()
|
junior.save()
|
||||||
return junior
|
return junior
|
||||||
|
|
||||||
def save(self, **kwargs):
|
def save(self, **kwargs):
|
||||||
|
"""Save the data into junior table"""
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
instance = super().save(**kwargs)
|
instance = super().save(**kwargs)
|
||||||
return instance
|
return instance
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"""Junior test file"""
|
||||||
|
"""Import TestCase"""
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
# Create your tests here.
|
# Create your tests here.
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
""" Urls files"""
|
""" Urls files"""
|
||||||
"""Django import"""
|
"""Django import"""
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from rest_framework.decorators import api_view
|
|
||||||
from .views import UpdateJuniorProfile, ValidateGuardianCode
|
from .views import UpdateJuniorProfile, ValidateGuardianCode
|
||||||
"""Third party import"""
|
"""Third party import"""
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
@@ -10,8 +9,11 @@ from rest_framework import routers
|
|||||||
router = routers.SimpleRouter()
|
router = routers.SimpleRouter()
|
||||||
|
|
||||||
"""API End points with router"""
|
"""API End points with router"""
|
||||||
router.register('complete-junior-profile', UpdateJuniorProfile, basename='profile-update')
|
"""Create junior profile API"""
|
||||||
|
router.register('create-junior-profile', UpdateJuniorProfile, basename='profile-update')
|
||||||
|
"""validate guardian code API"""
|
||||||
router.register('validate-guardian-code', ValidateGuardianCode, basename='validate-guardian-code')
|
router.register('validate-guardian-code', ValidateGuardianCode, basename='validate-guardian-code')
|
||||||
|
"""Define url pattern"""
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('api/v1/', include(router.urls)),
|
path('api/v1/', include(router.urls)),
|
||||||
]
|
]
|
||||||
@@ -1,40 +1,40 @@
|
|||||||
from django.shortcuts import render
|
"""Junior view file"""
|
||||||
from rest_framework import (pagination, viewsets, status, generics, mixins)
|
|
||||||
from rest_framework.decorators import action
|
|
||||||
from rest_framework.response import Response
|
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
|
||||||
# Create your views here.
|
|
||||||
from rest_framework import viewsets, status
|
from rest_framework import viewsets, status
|
||||||
from rest_framework.response import Response
|
|
||||||
from .serializers import CreateJuniorSerializer
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from base.constants import GUARDIAN, JUNIOR, SUPERUSER
|
"""Django app import"""
|
||||||
from junior.models import Junior
|
from junior.models import Junior
|
||||||
|
from .serializers import CreateJuniorSerializer
|
||||||
from guardian.models import Guardian
|
from guardian.models import Guardian
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
from account.utils import custom_response, custom_error_response
|
from account.utils import custom_response, custom_error_response
|
||||||
|
# Create your views here.
|
||||||
class UpdateJuniorProfile(viewsets.ViewSet):
|
class UpdateJuniorProfile(viewsets.ViewSet):
|
||||||
|
"""Update junior profile"""
|
||||||
serializer_class = CreateJuniorSerializer
|
serializer_class = CreateJuniorSerializer
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
serializer = CreateJuniorSerializer(context={"user":request.user,"first_name":request.data.get('first_name', ''),
|
"""Use CreateJuniorSerializer"""
|
||||||
"last_name": request.data.get('last_name',' ')}, data=request.data)
|
serializer = CreateJuniorSerializer(context={"user":request.user,
|
||||||
|
"first_name":request.data.get('first_name', ''),
|
||||||
|
"last_name": request.data.get('last_name',' ')},
|
||||||
|
data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
|
"""save serializer"""
|
||||||
serializer.save()
|
serializer.save()
|
||||||
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_error_response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
class ValidateGuardianCode(viewsets.ViewSet):
|
class ValidateGuardianCode(viewsets.ViewSet):
|
||||||
|
"""Check guardian code exist or not"""
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
guardian_code = request.data.get('guardian_code')
|
"""check guardian code"""
|
||||||
|
guardian_code = self.request.GET.get('guardian_code').split(',')
|
||||||
for code in guardian_code:
|
for code in guardian_code:
|
||||||
guardian_data = Guardian.objects.filter(guardian_code=code).exists()
|
guardian_data = Guardian.objects.filter(guardian_code=code).exists()
|
||||||
if guardian_data:
|
if guardian_data:
|
||||||
return custom_response(SUCCESS_CODE['3028'], response_status=status.HTTP_200_OK)
|
return custom_response(SUCCESS_CODE['3013'], response_status=status.HTTP_200_OK)
|
||||||
else:
|
else:
|
||||||
return custom_error_response(ERROR_CODE["2022"], response_status=status.HTTP_400_BAD_REQUEST)
|
return custom_error_response(ERROR_CODE["2022"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
"""Django's command-line utility for administrative tasks."""
|
"""Django's command-line utility for administrative tasks."""
|
||||||
|
"""Django import"""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""Main function"""
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'zod_bank.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'zod_bank.settings')
|
||||||
try:
|
try:
|
||||||
|
"""Import execute from command line function"""
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
|
"""Show Exception error"""
|
||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Couldn't import Django. Are you sure it's installed and "
|
"Couldn't import Django. Are you sure it's installed and "
|
||||||
"available on your PYTHONPATH environment variable? Did you "
|
"available on your PYTHONPATH environment variable? Did you "
|
||||||
@@ -23,17 +23,23 @@ django-celery-results==2.5.1
|
|||||||
django-cors-headers==4.1.0
|
django-cors-headers==4.1.0
|
||||||
django-dotenv==1.4.2
|
django-dotenv==1.4.2
|
||||||
django-extensions==3.2.3
|
django-extensions==3.2.3
|
||||||
|
django-phonenumber-field==7.1.0
|
||||||
|
django-render-block==0.9.2
|
||||||
django-ses==3.5.0
|
django-ses==3.5.0
|
||||||
|
django-smtp-ssl==1.0
|
||||||
django-storages==1.13.2
|
django-storages==1.13.2
|
||||||
|
django-templated-email==3.0.1
|
||||||
django-timezone-field==5.1
|
django-timezone-field==5.1
|
||||||
djangorestframework==3.14.0
|
djangorestframework==3.14.0
|
||||||
djangorestframework-simplejwt==5.2.2
|
djangorestframework-simplejwt==5.2.2
|
||||||
drf-yasg==1.21.6
|
drf-yasg==1.21.6
|
||||||
|
gunicorn==20.1.0
|
||||||
inflection==0.5.1
|
inflection==0.5.1
|
||||||
jmespath==0.10.0
|
jmespath==0.10.0
|
||||||
kombu==5.3.1
|
kombu==5.3.1
|
||||||
msgpack==1.0.5
|
msgpack==1.0.5
|
||||||
packaging==23.1
|
packaging==23.1
|
||||||
|
phonenumbers==8.13.15
|
||||||
prompt-toolkit==3.0.38
|
prompt-toolkit==3.0.38
|
||||||
psycopg==3.1.9
|
psycopg==3.1.9
|
||||||
pycparser==2.21
|
pycparser==2.21
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
"""
|
|
||||||
module containing override conflict error class
|
|
||||||
"""
|
|
||||||
# third party imports
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.exceptions import APIException
|
|
||||||
|
|
||||||
|
|
||||||
class ConflictError(APIException):
|
|
||||||
"""
|
|
||||||
Override conflict error
|
|
||||||
"""
|
|
||||||
status_code = status.HTTP_409_CONFLICT
|
|
||||||
default_detail = _('Not allowed request.')
|
|
||||||
default_code = 'conflict_error'
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
"""
|
|
||||||
This module contains search methods that can be used to search over a particular field in a specific model.
|
|
||||||
Update SEARCH_MAP dict for searching with model name and fields name
|
|
||||||
"""
|
|
||||||
# python imports
|
|
||||||
import operator
|
|
||||||
from functools import reduce
|
|
||||||
|
|
||||||
# third party imports
|
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from django.db.models import Q
|
|
||||||
|
|
||||||
SEARCH_MAP = {
|
|
||||||
get_user_model(): {'search_fields': ['first_name__icontains', 'last_name__icontains', 'username__icontains']}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def search_query(search_by, search_term):
|
|
||||||
"""
|
|
||||||
:param search_by: search fields
|
|
||||||
:param search_term: search value
|
|
||||||
:return: return query
|
|
||||||
"""
|
|
||||||
query = []
|
|
||||||
if search_by:
|
|
||||||
for key in search_by:
|
|
||||||
query.append({key: search_term})
|
|
||||||
return query
|
|
||||||
|
|
||||||
|
|
||||||
def get_search_fields(model):
|
|
||||||
"""
|
|
||||||
:param model: model name
|
|
||||||
:return: dict of searching field name
|
|
||||||
"""
|
|
||||||
return SEARCH_MAP[model]['search_fields']
|
|
||||||
|
|
||||||
|
|
||||||
def global_search(search_data, model_name):
|
|
||||||
"""
|
|
||||||
:param search_data: search value
|
|
||||||
:param model_name: model name
|
|
||||||
:return: query
|
|
||||||
"""
|
|
||||||
# get search fields for the above model
|
|
||||||
search_fields = get_search_fields(model_name)
|
|
||||||
# build query
|
|
||||||
query = search_query(search_fields, search_data)
|
|
||||||
return model_name.objects.filter(reduce(operator.or_, [Q(**x) for x in query]))
|
|
||||||
@@ -57,7 +57,7 @@ INSTALLED_APPS = [
|
|||||||
'junior',
|
'junior',
|
||||||
'guardian',
|
'guardian',
|
||||||
]
|
]
|
||||||
# CSRF_COOKIE_SECURE = False
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
@@ -168,35 +168,25 @@ CORS_ALLOW_HEADERS = (
|
|||||||
'x-requested-with',
|
'x-requested-with',
|
||||||
)
|
)
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
"""Static files (CSS, JavaScript, Images)
|
||||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
https://docs.djangoproject.com/en/3.0/howto/static-files/"""
|
||||||
|
|
||||||
#
|
|
||||||
# MAIL_MAILER='smtp'
|
|
||||||
# MAIL_HOST='smtp.gmail.com'
|
|
||||||
# MAIL_PORT=587
|
|
||||||
# mail_username='[email protected]'
|
|
||||||
# MAIL_PASSWORD='ghwdmznwwslvchga'
|
|
||||||
# MAIL_ENCRYPTION='tls'
|
|
||||||
# mail_from_address='[email protected]'
|
|
||||||
# MAIL_FROM_NAME="${APP_NAME}"
|
|
||||||
|
|
||||||
# MAIL_MAILER='smtp'
|
|
||||||
# MAIL_HOST='smtp.gmail.com'
|
|
||||||
# MAIL_PORT=587
|
|
||||||
# mail_username='[email protected]'
|
|
||||||
# MAIL_PASSWORD='jaijain0912@'
|
|
||||||
# MAIL_ENCRYPTION='tls'
|
|
||||||
# mail_from_address='[email protected]'
|
|
||||||
# MAIL_FROM_NAME="${APP_NAME}"
|
|
||||||
|
|
||||||
# Email settings
|
# Email settings
|
||||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
# EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||||
EMAIL_HOST = 'smtp.gmail.com'
|
# EMAIL_HOST = 'smtp.gmail.com'
|
||||||
EMAIL_PORT = 587
|
# EMAIL_PORT = 587
|
||||||
EMAIL_USE_TLS = True
|
# EMAIL_USE_TLS = True
|
||||||
EMAIL_HOST_USER = '[email protected]'
|
# EMAIL_HOST_USER = '[email protected]'
|
||||||
EMAIL_HOST_PASSWORD = 'ghwdmznwwslvchga' # Replace with your Gmail email password or App password
|
# # Replace with your Gmail email password or App password
|
||||||
|
# EMAIL_HOST_PASSWORD = 'ghwdmznwwslvchga'
|
||||||
|
|
||||||
|
EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS')
|
||||||
|
EMAIL_HOST = os.getenv('EMAIL_HOST')
|
||||||
|
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER')
|
||||||
|
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD')
|
||||||
|
EMAIL_PORT = os.getenv('EMAIL_PORT')
|
||||||
|
|
||||||
|
STATIC_URL = 'static/'
|
||||||
|
STATIC_ROOT = 'static'
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
|
||||||
Reference in New Issue
Block a user