mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-17 02:45:08 +00:00
force update and mail by celery task
This commit is contained in:
@ -5,7 +5,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
"""App django"""
|
||||
from account.utils import custom_error_response
|
||||
from account.models import UserDeviceDetails
|
||||
from account.models import UserDeviceDetails, ForceUpdate
|
||||
from base.messages import ERROR_CODE, SUCCESS_CODE
|
||||
from base.constants import NUMBER
|
||||
from junior.models import Junior
|
||||
@ -39,6 +39,8 @@ class CustomMiddleware(object):
|
||||
# Code to be executed after the view is called
|
||||
device_id = request.META.get('HTTP_DEVICE_ID')
|
||||
user_type = request.META.get('HTTP_USER_TYPE')
|
||||
version = request.META.get('HTTP_VERSION')
|
||||
device_type = str(request.META.get('HTTP_TYPE'))
|
||||
api_endpoint = request.path
|
||||
if request.user.is_authenticated:
|
||||
# device details
|
||||
@ -56,4 +58,6 @@ class CustomMiddleware(object):
|
||||
if device_id and not device_details and api_endpoint != '/api/v1/user/login/':
|
||||
custom_error = custom_error_response(ERROR_CODE['2037'], response_status=status.HTTP_404_NOT_FOUND)
|
||||
response = custom_response(custom_error)
|
||||
force_update = ForceUpdate.objects.filter(version=version, device_type=device_type).last()
|
||||
|
||||
return response
|
||||
|
28
account/migrations/0010_forceupdate.py
Normal file
28
account/migrations/0010_forceupdate.py
Normal file
@ -0,0 +1,28 @@
|
||||
# Generated by Django 4.2.2 on 2023-08-22 07:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('account', '0009_alter_userdevicedetails_device_id'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='ForceUpdate',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('version', models.CharField(blank=True, max_length=50, null=True)),
|
||||
('device_type', models.CharField(blank=True, choices=[('1', 'android'), ('2', 'ios')], default=None, max_length=15, null=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Force Update Version',
|
||||
'verbose_name_plural': 'Force Update Version',
|
||||
'db_table': 'force_update',
|
||||
},
|
||||
),
|
||||
]
|
@ -3,7 +3,7 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
"""App import"""
|
||||
from base.constants import USER_TYPE
|
||||
from base.constants import USER_TYPE, DEVICE_TYPE
|
||||
# Create your models here.
|
||||
|
||||
class UserProfile(models.Model):
|
||||
@ -165,3 +165,25 @@ class UserDeviceDetails(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return self.user.email
|
||||
|
||||
|
||||
|
||||
|
||||
class ForceUpdate(models.Model):
|
||||
"""
|
||||
Force update
|
||||
"""
|
||||
"""Version ID"""
|
||||
version = models.CharField(max_length=50, null=True, blank=True)
|
||||
device_type = models.CharField(max_length=15, choices=DEVICE_TYPE, null=True, blank=True, default=None)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta(object):
|
||||
""" Meta information """
|
||||
db_table = 'force_update'
|
||||
verbose_name = 'Force Update Version'
|
||||
verbose_name_plural = 'Force Update Version'
|
||||
|
||||
def __str__(self):
|
||||
return self.version
|
||||
|
@ -509,7 +509,7 @@ class ReSendEmailOtp(viewsets.ModelViewSet):
|
||||
email_data.otp = otp
|
||||
email_data.expired_at = expiry
|
||||
email_data.save()
|
||||
send_otp_email(request.data['email'], otp)
|
||||
send_otp_email.delay(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)
|
||||
|
@ -50,7 +50,10 @@ USER_TYPE = (
|
||||
('2', 'guardian'),
|
||||
('3', 'superuser')
|
||||
)
|
||||
|
||||
DEVICE_TYPE = (
|
||||
('1', 'android'),
|
||||
('2', 'ios')
|
||||
)
|
||||
USER_TYPE_FLAG = {
|
||||
"FIRST" : "1",
|
||||
"TWO" : "2",
|
||||
|
@ -73,7 +73,7 @@ class SignupViewset(viewsets.ModelViewSet):
|
||||
UserEmailOtp.objects.create(email=request.data['email'], otp=otp,
|
||||
user_type=str(request.data['user_type']), expired_at=expiry)
|
||||
"""Send email to the register user"""
|
||||
send_otp_email(request.data['email'], otp)
|
||||
send_otp_email.delay(request.data['email'], otp)
|
||||
UserDeviceDetails.objects.create(user=user, device_id=device_id)
|
||||
return custom_response(SUCCESS_CODE['3001'],
|
||||
response_status=status.HTTP_200_OK)
|
||||
|
@ -97,7 +97,7 @@ class CreateJuniorSerializer(serializers.ModelSerializer):
|
||||
if guardian_data:
|
||||
JuniorGuardianRelationship.objects.get_or_create(guardian=guardian_data, junior=junior)
|
||||
junior.guardian_code_status = str(NUMBER['three'])
|
||||
junior_approval_mail(user.email, user.first_name)
|
||||
junior_approval_mail.delay(user.email, user.first_name)
|
||||
send_notification_to_guardian.delay(APPROVED_JUNIOR, junior.auth.id, guardian_data.user.id, {})
|
||||
junior.dob = validated_data.get('dob', junior.dob)
|
||||
junior.passcode = validated_data.get('passcode', junior.passcode)
|
||||
@ -304,7 +304,7 @@ class AddJuniorSerializer(serializers.ModelSerializer):
|
||||
# add push notification
|
||||
UserNotification.objects.get_or_create(user=user_data)
|
||||
"""Notification email"""
|
||||
junior_notification_email(email, full_name, email, password)
|
||||
junior_notification_email.delay(email, full_name, email, password)
|
||||
# push notification
|
||||
send_notification_to_junior.delay(SKIPPED_PROFILE_SETUP, None, junior_data.auth.id, {})
|
||||
return junior_data
|
||||
@ -450,7 +450,7 @@ class AddGuardianSerializer(serializers.ModelSerializer):
|
||||
|
||||
"""Notification email"""
|
||||
junior_notification_email(email, full_name, email, password)
|
||||
junior_approval_mail(email, full_name)
|
||||
junior_approval_mail.delay(email, full_name)
|
||||
send_notification_to_junior.delay(INVITATION, guardian_data.user.id, junior_data.auth.id, {})
|
||||
send_notification_to_guardian.delay(ASSOCIATE_REQUEST, junior_data.auth.id, guardian_data.user.id, {})
|
||||
return guardian_data
|
||||
|
@ -14,6 +14,8 @@ from django.db.models import F
|
||||
# being part of the zod bank and access the platform
|
||||
# define junior notification email
|
||||
# junior approval email
|
||||
from celery import shared_task
|
||||
@shared_task()
|
||||
def junior_notification_email(recipient_email, full_name, email, password):
|
||||
"""Notification email"""
|
||||
from_email = settings.EMAIL_FROM_ADDRESS
|
||||
@ -32,7 +34,7 @@ def junior_notification_email(recipient_email, full_name, email, password):
|
||||
}
|
||||
)
|
||||
return full_name
|
||||
|
||||
@shared_task()
|
||||
def junior_approval_mail(guardian, full_name):
|
||||
"""junior approval mail"""
|
||||
from_email = settings.EMAIL_FROM_ADDRESS
|
||||
|
Reference in New Issue
Block a user