diff --git a/account/custom_middleware.py b/account/custom_middleware.py index c2125cd..3193fa9 100644 --- a/account/custom_middleware.py +++ b/account/custom_middleware.py @@ -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 diff --git a/account/migrations/0010_forceupdate.py b/account/migrations/0010_forceupdate.py new file mode 100644 index 0000000..84f5b12 --- /dev/null +++ b/account/migrations/0010_forceupdate.py @@ -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', + }, + ), + ] diff --git a/account/models.py b/account/models.py index 784a60e..c71181e 100644 --- a/account/models.py +++ b/account/models.py @@ -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 diff --git a/account/views.py b/account/views.py index e4051f4..84b6aaa 100644 --- a/account/views.py +++ b/account/views.py @@ -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) diff --git a/base/constants.py b/base/constants.py index d376971..1ab15a2 100644 --- a/base/constants.py +++ b/base/constants.py @@ -50,7 +50,10 @@ USER_TYPE = ( ('2', 'guardian'), ('3', 'superuser') ) - +DEVICE_TYPE = ( + ('1', 'android'), + ('2', 'ios') +) USER_TYPE_FLAG = { "FIRST" : "1", "TWO" : "2", diff --git a/guardian/views.py b/guardian/views.py index dd3a1ec..80c1d9b 100644 --- a/guardian/views.py +++ b/guardian/views.py @@ -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) diff --git a/junior/serializers.py b/junior/serializers.py index 1ca98e4..01e5adc 100644 --- a/junior/serializers.py +++ b/junior/serializers.py @@ -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 diff --git a/junior/utils.py b/junior/utils.py index ba177a8..4a6ee2b 100644 --- a/junior/utils.py +++ b/junior/utils.py @@ -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