mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 13:49:40 +00:00
Compare commits
12 Commits
demo-dev1
...
server_dem
Author | SHA1 | Date | |
---|---|---|---|
ad582d77d7 | |||
8ff142ce2f | |||
2086dcb472 | |||
d4eaaada74 | |||
396b4a32c3 | |||
232f082c77 | |||
aaa1730636 | |||
44b25dde3e | |||
b52819c033 | |||
9bd31f9e86 | |||
6374ea0a90 | |||
c115873972 |
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -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
|
||||
|
||||
# Register your models here.
|
||||
"""Import django app"""
|
||||
from .models import UserProfile, UserEmailOtp, UserPhoneOtp
|
||||
# Register your models here.
|
||||
@admin.register(UserProfile)
|
||||
class UserProfileAdmin(admin.ModelAdmin):
|
||||
"""User profile admin"""
|
||||
list_display = ['user']
|
||||
|
||||
def __str__(self):
|
||||
@ -12,14 +14,18 @@ class UserProfileAdmin(admin.ModelAdmin):
|
||||
|
||||
@admin.register(UserEmailOtp)
|
||||
class UserEmailOtpAdmin(admin.ModelAdmin):
|
||||
"""User Email otp admin"""
|
||||
list_display = ['email']
|
||||
|
||||
def __str__(self):
|
||||
"""Return object in email and otp format"""
|
||||
return self.email + '-' + self.otp
|
||||
|
||||
@admin.register(UserPhoneOtp)
|
||||
class UserPhoneOtpAdmin(admin.ModelAdmin):
|
||||
"""User Phone otp admin"""
|
||||
list_display = ['phone']
|
||||
|
||||
def __str__(self):
|
||||
"""Return object in phone number and otp format"""
|
||||
return self.phone + '-' + self.otp
|
@ -13,6 +13,7 @@ from rest_framework.decorators import action
|
||||
from django.contrib.auth import authenticate, login
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
|
||||
|
||||
class ResetPasswordSerializer(serializers.Serializer):
|
||||
"""Reset Password after verification"""
|
||||
verification_code = serializers.CharField(max_length=10)
|
||||
@ -62,7 +63,6 @@ class ChangePasswordSerializer(serializers.Serializer):
|
||||
user_details.set_password(new_password)
|
||||
user_details.save()
|
||||
return {'password':new_password}
|
||||
return user_details
|
||||
return ''
|
||||
|
||||
|
@ -11,7 +11,7 @@ router = routers.SimpleRouter()
|
||||
|
||||
"""API End points with router"""
|
||||
router.register('user', UserLogin, basename='user')
|
||||
router.register('superuser', UserLogin, basename='superuser')
|
||||
router.register('admin', UserLogin, basename='admin')
|
||||
router.register('send-phone-otp', SendPhoneOtp, basename='send-phone-otp')
|
||||
router.register('user-phone-verification', UserPhoneVerification, basename='user-phone-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
|
||||
import random
|
||||
from rest_framework import viewsets, status
|
||||
from rest_framework.response import Response
|
||||
|
@ -1,6 +1,7 @@
|
||||
from rest_framework import viewsets, status, views
|
||||
from rest_framework.decorators import action
|
||||
import random
|
||||
import logging
|
||||
from django.contrib.auth import authenticate, login
|
||||
from guardian.models import Guardian
|
||||
from junior.models import Junior
|
||||
@ -8,36 +9,30 @@ from account.models import UserProfile, UserPhoneOtp, UserEmailOtp
|
||||
from django.contrib.auth.models import User
|
||||
from .serializers import (SuperUserSerializer, GuardianSerializer, JuniorSerializer, EmailVerificationSerializer,
|
||||
ForgotPasswordSerializer, ResetPasswordSerializer, ChangePasswordSerializer)
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||
from rest_framework_simplejwt.tokens import RefreshToken
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from guardian.tasks import generate_otp
|
||||
from django.conf import settings
|
||||
from account.utils import send_otp_email
|
||||
from account.utils import custom_response, custom_error_response
|
||||
from django.core.mail import EmailMessage
|
||||
from django.core.mail import send_mail
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from templated_email import send_templated_mail
|
||||
import secrets
|
||||
|
||||
|
||||
class ChangePasswordAPIView(views.APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
def post(self, request):
|
||||
print("request.data====>",request.data)
|
||||
print("request.user====>", request.user)
|
||||
serializer = ChangePasswordSerializer(context=request.user, data=request.data)
|
||||
if serializer.is_valid():
|
||||
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)
|
||||
|
||||
class ResetPasswordAPIView(views.APIView):
|
||||
def post(self, request):
|
||||
print("request.data====>",request.data)
|
||||
serializer = ResetPasswordSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
@ -65,8 +60,11 @@ class ForgotPasswordAPIView(views.APIView):
|
||||
'verification_code': verification_code
|
||||
}
|
||||
)
|
||||
UserEmailOtp.objects.create(email=email, otp=verification_code)
|
||||
return custom_response(SUCCESS_CODE['3015'], {'verification_code': verification_code},
|
||||
user_data, created = UserEmailOtp.objects.get_or_create(email=email)
|
||||
if user_data:
|
||||
user_data.otp = verification_code
|
||||
user_data.save()
|
||||
return custom_response(SUCCESS_CODE['3015'],
|
||||
response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@ -74,24 +72,30 @@ class SendPhoneOtp(viewsets.ModelViewSet):
|
||||
"""Send otp on phone"""
|
||||
def create(self, request, *args, **kwargs):
|
||||
otp = generate_otp()
|
||||
UserPhoneOtp.objects.create(country_code=self.request.data['country_code'],
|
||||
phone=self.request.data['phone'], otp=otp)
|
||||
return custom_response(None, {'phone_otp':otp}, response_status=status.HTTP_200_OK)
|
||||
phone_number = self.request.data['phone']
|
||||
if phone_number.isdigit() and len(phone_number) == 10:
|
||||
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):
|
||||
"""Send otp on phone"""
|
||||
def list(self, request, *args, **kwargs):
|
||||
try:
|
||||
phone_data = UserPhoneOtp.objects.filter(phone=request.data['phone'],
|
||||
otp=request.data['otp']).last()
|
||||
phone_data = UserPhoneOtp.objects.filter(phone=self.request.GET.get('phone'),
|
||||
otp=self.request.GET.get('otp')).last()
|
||||
if phone_data:
|
||||
phone_data.is_verified = True
|
||||
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:
|
||||
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)
|
||||
|
||||
|
||||
@ -111,12 +115,11 @@ class UserLogin(viewsets.ViewSet):
|
||||
junior_data = Junior.objects.filter(auth__username=username, is_complete_profile=True).last()
|
||||
if 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)
|
||||
else:
|
||||
return custom_error_response(ERROR_CODE["2002"], response_status=status.HTTP_401_UNAUTHORIZED)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
user_profile_data = UserProfile.objects.filter(user__username=username).last()
|
||||
email_verified = UserEmailOtp.objects.filter(email=username).last()
|
||||
refresh = RefreshToken.for_user(user)
|
||||
@ -132,26 +135,50 @@ class UserLogin(viewsets.ViewSet):
|
||||
email_verified.otp = otp
|
||||
email_verified.save()
|
||||
data.update({"email_otp":otp})
|
||||
return custom_response(ERROR_CODE['2024'], {"email_otp":otp, "is_email_verified": is_verified},
|
||||
response_status=status.HTTP_400_BAD_REQUEST)
|
||||
return custom_response(ERROR_CODE['2024'], {"email_otp": otp, "is_email_verified": is_verified},
|
||||
response_status=status.HTTP_200_OK)
|
||||
data.update({"is_email_verified": is_verified})
|
||||
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):
|
||||
"""User Email verification"""
|
||||
serializer_class = EmailVerificationSerializer
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
try:
|
||||
email_data = UserEmailOtp.objects.filter(email=request.data['email'],
|
||||
otp=request.data['otp']).last()
|
||||
user_obj = User.objects.filter(username=self.request.GET.get('email')).last()
|
||||
email_data = UserEmailOtp.objects.filter(email=self.request.GET.get('email'),
|
||||
otp=self.request.GET.get('otp')).last()
|
||||
if email_data:
|
||||
email_data.is_verified = True
|
||||
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:
|
||||
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
return custom_error_response(ERROR_CODE["2008"], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
class ReSendEmailOtp(viewsets.ModelViewSet):
|
||||
@ -159,8 +186,11 @@ class ReSendEmailOtp(viewsets.ModelViewSet):
|
||||
def create(self, request, *args, **kwargs):
|
||||
otp = generate_otp()
|
||||
if User.objects.filter(email=request.data['email']):
|
||||
UserEmailOtp.objects.create(email=request.data['email'], otp=otp)
|
||||
return custom_response(None, {'email_otp': otp}, response_status=status.HTTP_200_OK)
|
||||
email_data, created = UserEmailOtp.objects.get_or_create(email=request.data['email'])
|
||||
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:
|
||||
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
|
||||
|
||||
# Define common file extention
|
||||
FILE_EXTENSION = ("gif", "jpeg", "jpg", "png", "svg", "csv", "doc", "docx", "odt", "pdf", "rtf", "txt", "wks", "wp",
|
||||
"wpd")
|
||||
FILE_EXTENSION = ("gif", "jpeg", "jpg", "png", "svg")
|
||||
|
||||
# Define file size in bytes(5MB = 5 * 1024 * 1024)
|
||||
FILE_SIZE = 5 * 1024 * 1024
|
||||
@ -42,53 +41,6 @@ GUARDIAN = 'guardian'
|
||||
JUNIOR = 'junior'
|
||||
SUPERUSER = 'superuser'
|
||||
# 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
|
||||
BYTE_IMAGE_SIZE = 1024
|
@ -63,7 +63,7 @@ SUCCESS_CODE = {
|
||||
# Success code for password reset
|
||||
"3006": "Your password has been reset successfully.",
|
||||
# Success code for password update
|
||||
"3007": "Your password has been updated successfully.",
|
||||
"3007": "Your password has been changed successfully.",
|
||||
# Success code for valid link
|
||||
"3008": "You have a valid link.",
|
||||
# Success code for logged out
|
||||
@ -74,7 +74,8 @@ SUCCESS_CODE = {
|
||||
"3012": "Phone OTP Verified successfully",
|
||||
"3013": "Valid Guardian code",
|
||||
"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 = {
|
@ -16,8 +16,8 @@ from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_200_OK
|
||||
from base import constants
|
||||
from base.constants import NUMBER
|
||||
# local import
|
||||
from resourcekit.settings import base_settings as settings
|
||||
from resourcekit.settings.base_settings import BASE_DIR
|
||||
from zod_bank.settings import base_settings as settings
|
||||
from zod_bank.settings.base_settings import BASE_DIR
|
||||
|
||||
|
||||
def image_upload(folder, file_name, data):
|
18
docker-compose.yml
Normal file
18
docker-compose.yml
Normal file
@ -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
|
||||
"""Import Django app"""
|
||||
from .models import Guardian
|
||||
# Register your models here.
|
||||
@admin.register(Guardian)
|
||||
class GuardianAdmin(admin.ModelAdmin):
|
||||
"""Junior Admin"""
|
||||
list_display = ['user', 'family_name']
|
||||
|
||||
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
|
||||
|
||||
|
||||
class CustodianConfig(AppConfig):
|
||||
"""Guardian config"""
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'guardian'
|
17
guardian/migrations/0002_remove_guardian_junior_code.py
Normal file
17
guardian/migrations/0002_remove_guardian_junior_code.py
Normal file
@ -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',
|
||||
),
|
||||
]
|
@ -1,24 +1,31 @@
|
||||
"""Guardian model file"""
|
||||
"""Third party Django app"""
|
||||
from django.db import models
|
||||
from django.contrib.auth import get_user_model
|
||||
"""Import Django app"""
|
||||
from base.constants import GENDERS
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
User = get_user_model()
|
||||
# Create your models here.
|
||||
|
||||
class Guardian(models.Model):
|
||||
"""Guardian model"""
|
||||
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)
|
||||
phone = models.CharField(max_length=31, null=True, blank=True, default=None)
|
||||
"""Personal info"""
|
||||
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)
|
||||
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)
|
||||
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_used = models.CharField(max_length=10, null=True, blank=True, default=None)
|
||||
"""Profile activity"""
|
||||
is_active = models.BooleanField(default=True)
|
||||
is_complete_profile = models.BooleanField(default=False)
|
||||
passcode = models.IntegerField(null=True, blank=True, default=None)
|
||||
"""Profile created and updated time"""
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
@ -28,4 +35,5 @@ class Guardian(models.Model):
|
||||
verbose_name = 'Guardian'
|
||||
|
||||
def __str__(self):
|
||||
"""Return email id"""
|
||||
return f'{self.user}'
|
@ -1,91 +1,116 @@
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth.models import User
|
||||
from .models import Guardian
|
||||
from django.db import transaction
|
||||
"""Serializer of Guardian"""
|
||||
"""Third party Django app"""
|
||||
import logging
|
||||
import random
|
||||
from account.models import UserProfile
|
||||
from junior.models import Junior
|
||||
from base.constants import GENDERS, GUARDIAN, JUNIOR, SUPERUSER
|
||||
from rest_framework import serializers
|
||||
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
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
"""User serializer"""
|
||||
auth_token = serializers.SerializerMethodField('get_auth_token')
|
||||
|
||||
|
||||
class Meta(object):
|
||||
"""Meta info"""
|
||||
model = User
|
||||
fields = ['email', 'password', 'auth_token']
|
||||
|
||||
def get_auth_token(self, obj):
|
||||
"""generate auth token"""
|
||||
refresh = RefreshToken.for_user(obj)
|
||||
access_token = str(refresh.access_token)
|
||||
return access_token
|
||||
def create(self, validated_data):
|
||||
"""fetch data"""
|
||||
email = validated_data.get('email')
|
||||
user_type = self.context
|
||||
password = validated_data.get('password')
|
||||
try:
|
||||
"""Create user profile"""
|
||||
user = User.objects.create_user(username=email, email=email, password=password)
|
||||
UserProfile.objects.create(user=user, user_type=user_type)
|
||||
return user
|
||||
except:
|
||||
except Exception as e:
|
||||
"""Error handling"""
|
||||
logging.error(e)
|
||||
raise serializers.ValidationError({"details":ERROR_CODE['2021']})
|
||||
|
||||
def save(self, **kwargs):
|
||||
"""save the data"""
|
||||
with transaction.atomic():
|
||||
instance = super().save(**kwargs)
|
||||
return instance
|
||||
|
||||
class CreateGuardianSerializer(serializers.ModelSerializer):
|
||||
"""Create guardian serializer"""
|
||||
"""Basic info"""
|
||||
first_name = serializers.SerializerMethodField('get_first_name')
|
||||
last_name = serializers.SerializerMethodField('get_last_name')
|
||||
email = serializers.SerializerMethodField('get_email')
|
||||
"""Contact details"""
|
||||
phone = serializers.CharField(max_length=20, required=False)
|
||||
family_name = serializers.CharField(max_length=100, required=False)
|
||||
country_code = serializers.IntegerField(required=False)
|
||||
family_name = serializers.CharField(max_length=100, required=False)
|
||||
dob = serializers.DateField(required=False)
|
||||
referral_code = serializers.CharField(max_length=100, required=False)
|
||||
|
||||
class Meta(object):
|
||||
"""Meta info"""
|
||||
model = Guardian
|
||||
fields = ['first_name', 'last_name', 'email', 'phone', 'family_name', 'gender', 'country_code', 'dob', 'referral_code', 'passcode',
|
||||
'is_complete_profile']
|
||||
fields = ['first_name', 'last_name', 'email', 'phone', 'family_name', 'gender', 'country_code',
|
||||
'dob', 'referral_code', 'passcode', 'is_complete_profile']
|
||||
|
||||
def get_first_name(self,obj):
|
||||
"""first name of guardian"""
|
||||
return obj.user.first_name
|
||||
|
||||
def get_last_name(self,obj):
|
||||
"""last name of guardian"""
|
||||
return obj.user.last_name
|
||||
|
||||
def get_email(self,obj):
|
||||
"""emailof guardian"""
|
||||
return obj.user.email
|
||||
|
||||
def create(self, validated_data):
|
||||
"""Create guardian profile"""
|
||||
user = User.objects.filter(username=self.context['user']).last()
|
||||
if user:
|
||||
"""Save first and last name of guardian"""
|
||||
user.first_name = self.context.get('first_name', user.first_name)
|
||||
user.last_name = self.context.get('last_name', user.last_name)
|
||||
user.save()
|
||||
"""Create guardian data"""
|
||||
guardian, created = Guardian.objects.get_or_create(user=self.context['user'])
|
||||
if created:
|
||||
"""Create referral code and guardian code"""
|
||||
guardian.referral_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
||||
guardian.guardian_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
||||
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.family_name = validated_data.get('family_name', guardian.family_name)
|
||||
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.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,
|
||||
guardian.dob, guardian.country_code, user.first_name, user.last_name])
|
||||
guardian.is_complete_profile = False
|
||||
if complete_profile_field:
|
||||
guardian.is_complete_profile = True
|
||||
guardian.country_code = validated_data.get('country_code', guardian.country_code)
|
||||
guardian.save()
|
||||
return guardian
|
||||
|
||||
def save(self, **kwargs):
|
||||
"""Save the data into junior table"""
|
||||
with transaction.atomic():
|
||||
instance = super().save(**kwargs)
|
||||
return instance
|
@ -1,3 +1,5 @@
|
||||
"""Test file of Guardian"""
|
||||
"""Third party Django app"""
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,17 +1,19 @@
|
||||
""" Urls files"""
|
||||
"""Django import"""
|
||||
from django.urls import path, include
|
||||
from rest_framework.decorators import api_view
|
||||
from .views import SignupViewset, UpdateGuardianProfile
|
||||
"""Third party import"""
|
||||
from rest_framework import routers
|
||||
|
||||
"""Router"""
|
||||
"""Define Router"""
|
||||
router = routers.SimpleRouter()
|
||||
|
||||
"""API End points with router"""
|
||||
"""Sign up API"""
|
||||
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 = [
|
||||
path('api/v1/', include(router.urls)),
|
||||
]
|
@ -1,45 +1,47 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import (pagination, viewsets, status, generics, mixins)
|
||||
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
|
||||
"""Views of Guardian"""
|
||||
"""Third party Django app"""
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from base.constants import GUARDIAN, JUNIOR, SUPERUSER
|
||||
from junior.models import Junior
|
||||
from rest_framework import viewsets, status
|
||||
"""Import Django app"""
|
||||
from .serializers import UserSerializer
|
||||
from .serializers import CreateGuardianSerializer
|
||||
from account.models import UserEmailOtp
|
||||
from .tasks import generate_otp
|
||||
from account.utils import send_otp_email
|
||||
from account.utils import custom_response, custom_error_response
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
|
||||
# Create your views here.
|
||||
class SignupViewset(viewsets.ModelViewSet):
|
||||
"""Signup view set"""
|
||||
serializer_class = UserSerializer
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""Create user profile"""
|
||||
serializer = UserSerializer(context=request.data['user_type'], data=request.data)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
"""Generate otp"""
|
||||
otp = generate_otp()
|
||||
UserEmailOtp.objects.create(email=request.data['email'], otp=otp)
|
||||
"""Send email to the register user"""
|
||||
send_otp_email(request.data['email'], otp)
|
||||
return custom_response(SUCCESS_CODE['3001'], {"email_otp": otp},
|
||||
response_status=status.HTTP_200_OK)
|
||||
return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
class UpdateGuardianProfile(viewsets.ViewSet):
|
||||
"""Update guardian profile"""
|
||||
serializer_class = CreateGuardianSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
serializer = CreateGuardianSerializer(context={"user":request.user,"first_name":request.data.get('first_name', ''),
|
||||
"last_name": request.data.get('last_name',' ')}, data=request.data)
|
||||
"""Create guardian profile"""
|
||||
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():
|
||||
"""save serializer"""
|
||||
serializer.save()
|
||||
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)
|
@ -1,9 +1,14 @@
|
||||
"""Junior admin"""
|
||||
"""Third party Django app"""
|
||||
from django.contrib import admin
|
||||
"""Import Django app"""
|
||||
from .models import Junior
|
||||
# Register your models here.
|
||||
@admin.register(Junior)
|
||||
class JuniorAdmin(admin.ModelAdmin):
|
||||
"""Junior Admin"""
|
||||
list_display = ['auth']
|
||||
|
||||
def __str__(self):
|
||||
"""Return email id"""
|
||||
return self.auth__email
|
@ -1,6 +1,8 @@
|
||||
"""App file"""
|
||||
"""Import AppConfig"""
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class JuniorConfig(AppConfig):
|
||||
"""Junior config"""
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'junior'
|
@ -1,25 +1,33 @@
|
||||
"""Junior model """
|
||||
"""Import django"""
|
||||
from django.db import models
|
||||
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
|
||||
"""Import django app"""
|
||||
from base.constants import GENDERS
|
||||
User = get_user_model()
|
||||
# Create your models here.
|
||||
|
||||
class Junior(models.Model):
|
||||
"""Junior model"""
|
||||
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)
|
||||
country_code = models.IntegerField(blank=True, null=True)
|
||||
"""Personal info"""
|
||||
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)
|
||||
# image = models.ImageField(upload_to='images/')
|
||||
"""Codes"""
|
||||
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)
|
||||
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)
|
||||
"""Profile activity"""
|
||||
is_active = models.BooleanField(default=True)
|
||||
is_complete_profile = models.BooleanField(default=False)
|
||||
passcode = models.IntegerField(null=True, blank=True, default=None)
|
||||
"""Profile created and updated time"""
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
@ -29,4 +37,5 @@ class Junior(models.Model):
|
||||
verbose_name = 'Junior'
|
||||
|
||||
def __str__(self):
|
||||
"""Return email id"""
|
||||
return f'{self.auth}'
|
@ -1,28 +1,29 @@
|
||||
"""Serializer file for junior"""
|
||||
"""Import Django 3rd party app"""
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth.models import User
|
||||
from .models import Guardian
|
||||
from django.db import transaction
|
||||
import random
|
||||
from account.models import UserProfile
|
||||
"""Import django app"""
|
||||
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):
|
||||
"""Serializer for Array field"""
|
||||
child = serializers.CharField()
|
||||
|
||||
def to_representation(self, data):
|
||||
"""to represent the data"""
|
||||
return data
|
||||
|
||||
def to_internal_value(self, data):
|
||||
"""internal value"""
|
||||
if isinstance(data, list):
|
||||
return data
|
||||
raise serializers.ValidationError({"details":"Invalid input. Expected a list of strings."})
|
||||
|
||||
|
||||
class CreateJuniorSerializer(serializers.ModelSerializer):
|
||||
"""Create junior serializer"""
|
||||
first_name = serializers.SerializerMethodField('get_first_name')
|
||||
last_name = serializers.SerializerMethodField('get_last_name')
|
||||
email = serializers.SerializerMethodField('get_email')
|
||||
@ -33,41 +34,59 @@ class CreateJuniorSerializer(serializers.ModelSerializer):
|
||||
guardian_code = ListCharField(required=False)
|
||||
|
||||
class Meta(object):
|
||||
"""Meta info"""
|
||||
model = Junior
|
||||
fields = ['first_name', 'last_name', 'email', 'phone', 'gender', 'country_code', 'dob', 'referral_code',
|
||||
'passcode', 'is_complete_profile', 'guardian_code']
|
||||
|
||||
def get_first_name(self,obj):
|
||||
"""first name of junior"""
|
||||
return obj.auth.first_name
|
||||
|
||||
def get_last_name(self,obj):
|
||||
"""last name of junior"""
|
||||
return obj.auth.last_name
|
||||
|
||||
def get_email(self,obj):
|
||||
"""email of junior"""
|
||||
return obj.auth.email
|
||||
|
||||
def create(self, validated_data):
|
||||
"""Create junior profile"""
|
||||
user = User.objects.filter(username=self.context['user']).last()
|
||||
if user:
|
||||
"""Save first and last name of junior"""
|
||||
user.first_name = self.context.get('first_name', user.first_name)
|
||||
user.last_name = self.context.get('last_name', user.last_name)
|
||||
user.save()
|
||||
"""Create junior data"""
|
||||
junior, created = Junior.objects.get_or_create(auth=self.context['user'])
|
||||
if created:
|
||||
"""Create referral code and junior code"""
|
||||
junior.referral_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
||||
junior.junior_code = ''.join([str(random.randrange(9)) for _ in range(4)])
|
||||
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)
|
||||
"""Update guardian code"""
|
||||
junior.guardian_code = validated_data.get('guardian_code', junior.guardian_code)
|
||||
junior.dob = validated_data.get('dob',junior.dob)
|
||||
junior.passcode = validated_data.get('passcode', junior.passcode)
|
||||
junior.is_complete_profile = validated_data.get('is_complete_profile', junior.is_complete_profile)
|
||||
"""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.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()
|
||||
return junior
|
||||
|
||||
def save(self, **kwargs):
|
||||
"""Save the data into junior table"""
|
||||
with transaction.atomic():
|
||||
instance = super().save(**kwargs)
|
||||
return instance
|
@ -1,3 +1,5 @@
|
||||
"""Junior test file"""
|
||||
"""Import TestCase"""
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,7 +1,6 @@
|
||||
""" Urls files"""
|
||||
"""Django import"""
|
||||
from django.urls import path, include
|
||||
from rest_framework.decorators import api_view
|
||||
from .views import UpdateJuniorProfile, ValidateGuardianCode
|
||||
"""Third party import"""
|
||||
from rest_framework import routers
|
||||
@ -10,8 +9,11 @@ from rest_framework import routers
|
||||
router = routers.SimpleRouter()
|
||||
|
||||
"""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')
|
||||
"""Define url pattern"""
|
||||
urlpatterns = [
|
||||
path('api/v1/', include(router.urls)),
|
||||
]
|
@ -1,40 +1,40 @@
|
||||
from django.shortcuts import render
|
||||
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.
|
||||
"""Junior view file"""
|
||||
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 base.constants import GUARDIAN, JUNIOR, SUPERUSER
|
||||
"""Django app import"""
|
||||
from junior.models import Junior
|
||||
from .serializers import CreateJuniorSerializer
|
||||
from guardian.models import Guardian
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from account.utils import custom_response, custom_error_response
|
||||
|
||||
# Create your views here.
|
||||
class UpdateJuniorProfile(viewsets.ViewSet):
|
||||
"""Update junior profile"""
|
||||
serializer_class = CreateJuniorSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
serializer = CreateJuniorSerializer(context={"user":request.user,"first_name":request.data.get('first_name', ''),
|
||||
"last_name": request.data.get('last_name',' ')}, data=request.data)
|
||||
"""Use CreateJuniorSerializer"""
|
||||
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():
|
||||
"""save serializer"""
|
||||
serializer.save()
|
||||
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):
|
||||
"""Check guardian code exist or not"""
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
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:
|
||||
guardian_data = Guardian.objects.filter(guardian_code=code).exists()
|
||||
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:
|
||||
return custom_error_response(ERROR_CODE["2022"], response_status=status.HTTP_400_BAD_REQUEST)
|
@ -1,14 +1,18 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
"""Django import"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Main function"""
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'zod_bank.settings')
|
||||
try:
|
||||
"""Import execute from command line function"""
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
"""Show Exception error"""
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"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-dotenv==1.4.2
|
||||
django-extensions==3.2.3
|
||||
django-phonenumber-field==7.1.0
|
||||
django-render-block==0.9.2
|
||||
django-ses==3.5.0
|
||||
django-smtp-ssl==1.0
|
||||
django-storages==1.13.2
|
||||
django-templated-email==3.0.1
|
||||
django-timezone-field==5.1
|
||||
djangorestframework==3.14.0
|
||||
djangorestframework-simplejwt==5.2.2
|
||||
drf-yasg==1.21.6
|
||||
gunicorn==20.1.0
|
||||
inflection==0.5.1
|
||||
jmespath==0.10.0
|
||||
kombu==5.3.1
|
||||
msgpack==1.0.5
|
||||
packaging==23.1
|
||||
phonenumbers==8.13.15
|
||||
prompt-toolkit==3.0.38
|
||||
psycopg==3.1.9
|
||||
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',
|
||||
'guardian',
|
||||
]
|
||||
# CSRF_COOKIE_SECURE = False
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
@ -168,27 +168,9 @@ CORS_ALLOW_HEADERS = (
|
||||
'x-requested-with',
|
||||
)
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||
"""Static files (CSS, JavaScript, Images)
|
||||
https://docs.djangoproject.com/en/3.0/howto/static-files/"""
|
||||
|
||||
#
|
||||
# MAIL_MAILER='smtp'
|
||||
# MAIL_HOST='smtp.gmail.com'
|
||||
# MAIL_PORT=587
|
||||
# mail_username='infozodbank@gmail.com'
|
||||
# MAIL_PASSWORD='ghwdmznwwslvchga'
|
||||
# MAIL_ENCRYPTION='tls'
|
||||
# mail_from_address='infozodbank@gmail.com'
|
||||
# MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
# MAIL_MAILER='smtp'
|
||||
# MAIL_HOST='smtp.gmail.com'
|
||||
# MAIL_PORT=587
|
||||
# mail_username='ankita.jain@kiwitech.com'
|
||||
# MAIL_PASSWORD='jaijain0912@'
|
||||
# MAIL_ENCRYPTION='tls'
|
||||
# mail_from_address='infozodbank@gmail.com'
|
||||
# MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
# Email settings
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
@ -196,7 +178,7 @@ EMAIL_HOST = 'smtp.gmail.com'
|
||||
EMAIL_PORT = 587
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST_USER = 'infozodbank@gmail.com'
|
||||
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'
|
||||
|
||||
STATIC_URL = '/static/'
|
Reference in New Issue
Block a user