mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-14 17:45:46 +00:00
added optional user as name
This commit is contained in:
@ -37,6 +37,27 @@ def send_email_otp(email, verification_code):
|
||||
return True
|
||||
|
||||
|
||||
@shared_task
|
||||
def send_mail(recipient_list, template, context: dict = None):
|
||||
"""
|
||||
used to send otp on email
|
||||
:param context:
|
||||
:param recipient_list: e-mail list
|
||||
:param template: email template
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
from_email = settings.EMAIL_FROM_ADDRESS
|
||||
recipient_list = recipient_list
|
||||
send_templated_mail(
|
||||
template_name=template,
|
||||
from_email=from_email,
|
||||
recipient_list=recipient_list,
|
||||
context=context
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
@shared_task()
|
||||
def notify_task_expiry():
|
||||
"""
|
||||
|
@ -9,6 +9,7 @@ from firebase_admin.messaging import Message, Notification as FirebaseNotificati
|
||||
# django imports
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
# local imports
|
||||
from account.models import UserNotification
|
||||
from account.utils import get_user_full_name
|
||||
from base.constants import GUARDIAN, JUNIOR
|
||||
@ -17,8 +18,6 @@ from junior.models import Junior
|
||||
from notifications.constants import NOTIFICATION_DICT
|
||||
from notifications.models import Notification
|
||||
|
||||
# local imports
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
@ -105,7 +104,7 @@ def send_notification(notification_type, from_user_id, from_user_type, to_user_i
|
||||
notification_data.update({'badge': Notification.objects.filter(notification_to=to_user, is_read=False).count()})
|
||||
Notification.objects.create(notification_type=notification_type, notification_from=from_user,
|
||||
notification_to=to_user, data=notification_data)
|
||||
if user_notification_type.push_notification:
|
||||
if user_notification_type and user_notification_type.push_notification:
|
||||
send_push(to_user, push_data)
|
||||
|
||||
|
||||
|
@ -10,10 +10,8 @@ from rest_framework import viewsets, status, views
|
||||
|
||||
# local imports
|
||||
from account.utils import custom_response, custom_error_response
|
||||
from base.constants import JUNIOR, GUARDIAN
|
||||
from base.messages import SUCCESS_CODE, ERROR_CODE
|
||||
from base.tasks import notify_task_expiry
|
||||
from guardian.models import Guardian
|
||||
from notifications.constants import TEST_NOTIFICATION
|
||||
from notifications.serializers import RegisterDevice, NotificationListSerializer, ReadNotificationSerializer
|
||||
from notifications.utils import send_notification
|
||||
|
@ -7,6 +7,7 @@ from rest_framework import serializers
|
||||
# django imports
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from account.utils import get_user_full_name
|
||||
# local imports
|
||||
from base.constants import USER_TYPE
|
||||
|
||||
@ -74,6 +75,7 @@ class UserCSVReportSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
user csv/xls report serializer
|
||||
"""
|
||||
name = serializers.SerializerMethodField()
|
||||
phone_number = serializers.SerializerMethodField()
|
||||
user_type = serializers.SerializerMethodField()
|
||||
is_active = serializers.SerializerMethodField()
|
||||
@ -84,7 +86,15 @@ class UserCSVReportSerializer(serializers.ModelSerializer):
|
||||
meta class
|
||||
"""
|
||||
model = USER
|
||||
fields = ('first_name', 'last_name', 'email', 'phone_number', 'user_type', 'is_active', 'date_joined')
|
||||
fields = ('name', 'email', 'phone_number', 'user_type', 'is_active', 'date_joined')
|
||||
|
||||
@staticmethod
|
||||
def get_name(obj):
|
||||
"""
|
||||
:param obj: user object
|
||||
:return: full name
|
||||
"""
|
||||
return get_user_full_name(obj)
|
||||
|
||||
@staticmethod
|
||||
def get_phone_number(obj):
|
||||
|
@ -14,7 +14,7 @@ from account.models import UserEmailOtp
|
||||
from base.constants import USER_TYPE
|
||||
from base.messages import ERROR_CODE
|
||||
from guardian.tasks import generate_otp
|
||||
from base.tasks import send_email_otp
|
||||
from base.tasks import send_mail
|
||||
|
||||
USER = get_user_model()
|
||||
|
||||
@ -48,11 +48,13 @@ class AdminOTPSerializer(serializers.ModelSerializer):
|
||||
:return: user_data
|
||||
"""
|
||||
email = validated_data['email']
|
||||
|
||||
verification_code = generate_otp()
|
||||
|
||||
template = 'email_reset_verification.email'
|
||||
# Send the verification code to the user's email
|
||||
send_email_otp.delay(email, verification_code)
|
||||
data = {
|
||||
"verification_code": verification_code
|
||||
}
|
||||
send_mail.delay([email], template, data)
|
||||
|
||||
expiry = timezone.now() + timezone.timedelta(days=1)
|
||||
user_data, created = UserEmailOtp.objects.update_or_create(email=email,
|
||||
|
@ -5,6 +5,7 @@ web_admin user_management serializers file
|
||||
from rest_framework import serializers
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from account.utils import get_user_full_name
|
||||
from base.constants import USER_TYPE, GUARDIAN, JUNIOR
|
||||
# local imports
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
@ -37,7 +38,7 @@ class UserManagementListSerializer(serializers.ModelSerializer):
|
||||
:param obj: user object
|
||||
:return: full name
|
||||
"""
|
||||
return f"{obj.first_name} {obj.last_name}" if obj.last_name else obj.first_name
|
||||
return get_user_full_name(obj)
|
||||
|
||||
@staticmethod
|
||||
def get_country_code(obj):
|
||||
@ -144,7 +145,7 @@ class GuardianSerializer(serializers.ModelSerializer):
|
||||
:param obj: guardian object
|
||||
:return: full name
|
||||
"""
|
||||
return f"{obj.user.first_name} {obj.user.last_name}" if obj.user.last_name else obj.user.first_name
|
||||
return get_user_full_name(obj.user)
|
||||
|
||||
@staticmethod
|
||||
def get_first_name(obj):
|
||||
@ -222,7 +223,7 @@ class JuniorSerializer(serializers.ModelSerializer):
|
||||
:param obj: junior object
|
||||
:return: full name
|
||||
"""
|
||||
return f"{obj.auth.first_name} {obj.auth.last_name}" if obj.auth.last_name else obj.auth.first_name
|
||||
return get_user_full_name(obj.auth)
|
||||
|
||||
@staticmethod
|
||||
def get_first_name(obj):
|
||||
|
@ -107,13 +107,15 @@ class AnalyticsViewSet(GenericViewSet):
|
||||
|
||||
assign_tasks = JuniorTask.objects.filter(
|
||||
created_at__range=[start_date, (end_date + datetime.timedelta(days=1))]
|
||||
).exclude(task_status__in=[PENDING, EXPIRED])
|
||||
)
|
||||
|
||||
data = {
|
||||
'task_completed': assign_tasks.filter(task_status=COMPLETED).count(),
|
||||
'task_pending': assign_tasks.filter(task_status=PENDING).count(),
|
||||
'task_in_progress': assign_tasks.filter(task_status=IN_PROGRESS).count(),
|
||||
'task_requested': assign_tasks.filter(task_status=REQUESTED).count(),
|
||||
'task_rejected': assign_tasks.filter(task_status=REJECTED).count(),
|
||||
'task_expired': assign_tasks.filter(task_status=EXPIRED).count(),
|
||||
}
|
||||
|
||||
return custom_response(None, data)
|
||||
@ -169,10 +171,9 @@ class AnalyticsViewSet(GenericViewSet):
|
||||
serializer = UserCSVReportSerializer(queryset, many=True)
|
||||
|
||||
df_users = pd.DataFrame([
|
||||
{'Name': f"{user['first_name']} {user['last_name']}",
|
||||
'Email': user['email'], 'Phone Number': user['phone_number'],
|
||||
'User Type': user['user_type'], 'Status': user['is_active'],
|
||||
'Date Joined': user['date_joined']}
|
||||
{'Name': user['name'], 'Email': user['email'],
|
||||
'Phone Number': user['phone_number'], 'User Type': user['user_type'],
|
||||
'Status': user['is_active'], 'Date Joined': user['date_joined']}
|
||||
for user in serializer.data
|
||||
])
|
||||
write_excel_worksheet(worksheet, df_users)
|
||||
@ -181,7 +182,7 @@ class AnalyticsViewSet(GenericViewSet):
|
||||
elif sheet_name == 'Assign Tasks':
|
||||
assign_tasks = JuniorTask.objects.filter(
|
||||
created_at__range=[start_date, (end_date + datetime.timedelta(days=1))]
|
||||
).exclude(task_status__in=[PENDING, EXPIRED])
|
||||
)
|
||||
|
||||
df_tasks = pd.DataFrame([
|
||||
{'Task Name': task.task_name, 'Task Status': dict(TASK_STATUS).get(task.task_status).capitalize()}
|
||||
|
Reference in New Issue
Block a user