mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 18:36:18 +00:00
changes in task list API and add special character in password for added junior
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
"""Account utils"""
|
"""Account utils"""
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
|
import random
|
||||||
"""Import django"""
|
"""Import django"""
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from rest_framework import viewsets, status
|
from rest_framework import viewsets, status
|
||||||
@ -289,3 +289,27 @@ def get_user_full_name(user_obj):
|
|||||||
to get user's full name
|
to get user's full name
|
||||||
"""
|
"""
|
||||||
return f"{user_obj.first_name} {user_obj.last_name}" if user_obj.first_name or user_obj.last_name else "User"
|
return f"{user_obj.first_name} {user_obj.last_name}" if user_obj.first_name or user_obj.last_name else "User"
|
||||||
|
|
||||||
|
def make_special_password(length=10):
|
||||||
|
# Define character sets
|
||||||
|
lowercase_letters = string.ascii_lowercase
|
||||||
|
uppercase_letters = string.ascii_uppercase
|
||||||
|
digits = string.digits
|
||||||
|
special_characters = '!@#$%^&*()_-+=<>?/[]{}|'
|
||||||
|
|
||||||
|
# Combine character sets
|
||||||
|
all_characters = lowercase_letters + uppercase_letters + digits + special_characters
|
||||||
|
|
||||||
|
# Create a password with random characters
|
||||||
|
password = (
|
||||||
|
random.choice(lowercase_letters) +
|
||||||
|
random.choice(uppercase_letters) +
|
||||||
|
random.choice(digits) +
|
||||||
|
random.choice(special_characters) +
|
||||||
|
''.join(random.choice(all_characters) for _ in range(length - 4))
|
||||||
|
)
|
||||||
|
|
||||||
|
# Shuffle the characters to make it more random
|
||||||
|
password_list = list(password)
|
||||||
|
random.shuffle(password_list)
|
||||||
|
return ''.join(password_list)
|
||||||
|
@ -136,7 +136,8 @@ class TaskListAPIView(viewsets.ModelViewSet):
|
|||||||
Params
|
Params
|
||||||
status
|
status
|
||||||
search
|
search
|
||||||
page"""
|
page
|
||||||
|
junior"""
|
||||||
serializer_class = TaskDetailsSerializer
|
serializer_class = TaskDetailsSerializer
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
filter_backends = (SearchFilter,)
|
filter_backends = (SearchFilter,)
|
||||||
@ -156,9 +157,17 @@ class TaskListAPIView(viewsets.ModelViewSet):
|
|||||||
"""Create guardian profile"""
|
"""Create guardian profile"""
|
||||||
status_value = self.request.GET.get('status')
|
status_value = self.request.GET.get('status')
|
||||||
current_page = self.request.GET.get('page')
|
current_page = self.request.GET.get('page')
|
||||||
|
junior = self.request.GET.get('junior')
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
if status_value and status_value != '0':
|
task_status = ['1']
|
||||||
queryset = queryset.filter(task_status=status_value)
|
if str(status_value) == '2':
|
||||||
|
task_status = ['2', '4']
|
||||||
|
elif str(status_value) == '3':
|
||||||
|
task_status = ['3', '5', '6']
|
||||||
|
if status_value and not junior:
|
||||||
|
queryset = queryset.filter(task_status__in=task_status)
|
||||||
|
elif status_value and junior:
|
||||||
|
queryset = queryset.filter(task_status__in=task_status,junior=int(junior))
|
||||||
paginator = self.pagination_class()
|
paginator = self.pagination_class()
|
||||||
total_count = len(queryset)
|
total_count = len(queryset)
|
||||||
total_pages = math.ceil(total_count/10)
|
total_pages = math.ceil(total_count/10)
|
||||||
|
@ -11,7 +11,7 @@ from django.utils import timezone
|
|||||||
from rest_framework_simplejwt.tokens import RefreshToken
|
from rest_framework_simplejwt.tokens import RefreshToken
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from account.utils import send_otp_email, generate_code
|
from account.utils import send_otp_email, generate_code, make_special_password
|
||||||
from junior.models import Junior, JuniorPoints, JuniorGuardianRelationship, JuniorArticlePoints, FAQ
|
from junior.models import Junior, JuniorPoints, JuniorGuardianRelationship, JuniorArticlePoints, FAQ
|
||||||
from guardian.tasks import generate_otp
|
from guardian.tasks import generate_otp
|
||||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||||
@ -297,8 +297,8 @@ class AddJuniorSerializer(serializers.ModelSerializer):
|
|||||||
user_data = User.objects.create(username=email, email=email,
|
user_data = User.objects.create(username=email, email=email,
|
||||||
first_name=self.context['first_name'],
|
first_name=self.context['first_name'],
|
||||||
last_name=self.context['last_name'])
|
last_name=self.context['last_name'])
|
||||||
password = User.objects.make_random_password()
|
special_password = make_special_password()
|
||||||
user_data.set_password(password)
|
user_data.set_password(special_password)
|
||||||
user_data.save()
|
user_data.save()
|
||||||
junior_data = Junior.objects.create(auth=user_data, gender=validated_data.get('gender'),
|
junior_data = Junior.objects.create(auth=user_data, gender=validated_data.get('gender'),
|
||||||
image=profile_image,
|
image=profile_image,
|
||||||
@ -321,7 +321,7 @@ class AddJuniorSerializer(serializers.ModelSerializer):
|
|||||||
# add push notification
|
# add push notification
|
||||||
UserNotification.objects.get_or_create(user=user_data)
|
UserNotification.objects.get_or_create(user=user_data)
|
||||||
"""Notification email"""
|
"""Notification email"""
|
||||||
junior_notification_email.delay(email, full_name, email, password)
|
junior_notification_email.delay(email, full_name, email, special_password)
|
||||||
# push notification
|
# push notification
|
||||||
send_notification.delay(ASSOCIATE_JUNIOR, None, None, junior_data.auth.id, {})
|
send_notification.delay(ASSOCIATE_JUNIOR, None, None, junior_data.auth.id, {})
|
||||||
return junior_data
|
return junior_data
|
||||||
|
@ -369,8 +369,13 @@ class JuniorTaskListAPIView(viewsets.ModelViewSet):
|
|||||||
status_value = self.request.GET.get('status')
|
status_value = self.request.GET.get('status')
|
||||||
current_page = self.request.GET.get('page')
|
current_page = self.request.GET.get('page')
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
if status_value and status_value != '0':
|
task_status = ['1']
|
||||||
queryset = queryset.filter(task_status=status_value)
|
if str(status_value) == '2':
|
||||||
|
task_status = ['2', '4']
|
||||||
|
elif str(status_value) == '3':
|
||||||
|
task_status = ['3', '5', '6']
|
||||||
|
if status_value:
|
||||||
|
queryset = queryset.filter(task_status__in=task_status)
|
||||||
paginator = self.pagination_class()
|
paginator = self.pagination_class()
|
||||||
total_count = len(queryset)
|
total_count = len(queryset)
|
||||||
total_pages = math.ceil(total_count / 10)
|
total_pages = math.ceil(total_count / 10)
|
||||||
|
Reference in New Issue
Block a user