mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
change method to get real time
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
"""Serializer of Guardian"""
|
"""Serializer of Guardian"""
|
||||||
"""Third party Django app"""
|
# third party imports
|
||||||
import logging
|
import logging
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
# Import Refresh token of jwt
|
# Import Refresh token of jwt
|
||||||
@ -7,7 +7,8 @@ from rest_framework_simplejwt.tokens import RefreshToken
|
|||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
"""Import Django app"""
|
import pytz
|
||||||
|
from django.utils import timezone
|
||||||
# Import guardian's model,
|
# Import guardian's model,
|
||||||
# Import junior's model,
|
# Import junior's model,
|
||||||
# Import account's model,
|
# Import account's model,
|
||||||
@ -16,7 +17,7 @@ from datetime import datetime, time
|
|||||||
# Import messages from
|
# Import messages from
|
||||||
# base package,
|
# base package,
|
||||||
# Import some functions
|
# Import some functions
|
||||||
# from utils file"""
|
# local imports
|
||||||
from .models import Guardian, JuniorTask
|
from .models import Guardian, JuniorTask
|
||||||
from account.models import UserProfile, UserEmailOtp, UserNotification
|
from account.models import UserProfile, UserEmailOtp, UserNotification
|
||||||
from account.utils import generate_code
|
from account.utils import generate_code
|
||||||
@ -222,12 +223,9 @@ class TaskDetailsSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
def get_remaining_time(self, obj):
|
def get_remaining_time(self, obj):
|
||||||
""" remaining time to complete task"""
|
""" remaining time to complete task"""
|
||||||
import pytz
|
|
||||||
from django.utils import timezone
|
|
||||||
due_date_datetime = datetime.combine(obj.due_date, datetime.max.time())
|
due_date_datetime = datetime.combine(obj.due_date, datetime.max.time())
|
||||||
# fetch real time
|
# fetch real time
|
||||||
# current_datetime = real_time()
|
# current_datetime = real_time()
|
||||||
print(due_date_datetime.astimezone(pytz.utc), datetime.now(pytz.utc), timezone.now().astimezone(pytz.utc))
|
|
||||||
# new code
|
# new code
|
||||||
due_date_datetime = due_date_datetime.astimezone(pytz.utc)
|
due_date_datetime = due_date_datetime.astimezone(pytz.utc)
|
||||||
current_datetime = timezone.now().astimezone(pytz.utc)
|
current_datetime = timezone.now().astimezone(pytz.utc)
|
||||||
@ -260,7 +258,10 @@ class TaskDetailsjuniorSerializer(serializers.ModelSerializer):
|
|||||||
""" remaining time to complete task"""
|
""" remaining time to complete task"""
|
||||||
due_date_datetime = datetime.combine(obj.due_date, datetime.max.time())
|
due_date_datetime = datetime.combine(obj.due_date, datetime.max.time())
|
||||||
# fetch real time
|
# fetch real time
|
||||||
current_datetime = real_time()
|
# current_datetime = real_time()
|
||||||
|
# new code
|
||||||
|
due_date_datetime = due_date_datetime.astimezone(pytz.utc)
|
||||||
|
current_datetime = timezone.now().astimezone(pytz.utc)
|
||||||
# Perform the subtraction
|
# Perform the subtraction
|
||||||
if due_date_datetime > current_datetime:
|
if due_date_datetime > current_datetime:
|
||||||
time_difference = due_date_datetime - current_datetime
|
time_difference = due_date_datetime - current_datetime
|
||||||
@ -377,7 +378,8 @@ class ApproveTaskSerializer(serializers.ModelSerializer):
|
|||||||
# update total task point
|
# update total task point
|
||||||
junior_data.total_points = junior_data.total_points + instance.points
|
junior_data.total_points = junior_data.total_points + instance.points
|
||||||
# update complete time of task
|
# update complete time of task
|
||||||
instance.completed_on = real_time()
|
# instance.completed_on = real_time()
|
||||||
|
instance.completed_on = timezone.now().astimezone(pytz.utc)
|
||||||
send_notification.delay(TASK_POINTS, None, junior_details.auth.id, {})
|
send_notification.delay(TASK_POINTS, None, junior_details.auth.id, {})
|
||||||
else:
|
else:
|
||||||
# reject the task
|
# reject the task
|
||||||
@ -386,7 +388,8 @@ class ApproveTaskSerializer(serializers.ModelSerializer):
|
|||||||
# update total task point
|
# update total task point
|
||||||
junior_data.total_points = junior_data.total_points - instance.points
|
junior_data.total_points = junior_data.total_points - instance.points
|
||||||
# update reject time of task
|
# update reject time of task
|
||||||
instance.rejected_on = real_time()
|
# instance.rejected_on = real_time()
|
||||||
|
instance.rejected_on = timezone.now().astimezone(pytz.utc)
|
||||||
send_notification.delay(TASK_REJECTED, None, junior_details.auth.id, {})
|
send_notification.delay(TASK_REJECTED, None, junior_details.auth.id, {})
|
||||||
instance.save()
|
instance.save()
|
||||||
junior_data.save()
|
junior_data.save()
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
"""Serializer file for junior"""
|
"""Serializer file for junior"""
|
||||||
"""Import Django 3rd party app"""
|
# third party imports
|
||||||
|
import pytz
|
||||||
|
|
||||||
|
# django imports
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
@ -7,7 +10,7 @@ from datetime import datetime
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from rest_framework_simplejwt.tokens import RefreshToken
|
from rest_framework_simplejwt.tokens import RefreshToken
|
||||||
|
|
||||||
"""Import django app"""
|
# local imports
|
||||||
from account.utils import send_otp_email, generate_code
|
from account.utils import send_otp_email, generate_code
|
||||||
from junior.models import Junior, JuniorPoints, JuniorGuardianRelationship
|
from junior.models import Junior, JuniorPoints, JuniorGuardianRelationship
|
||||||
from guardian.tasks import generate_otp
|
from guardian.tasks import generate_otp
|
||||||
@ -320,7 +323,8 @@ class CompleteTaskSerializer(serializers.ModelSerializer):
|
|||||||
fields = ('id', 'image')
|
fields = ('id', 'image')
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
instance.image = validated_data.get('image', instance.image)
|
instance.image = validated_data.get('image', instance.image)
|
||||||
instance.requested_on = real_time()
|
# instance.requested_on = real_time()
|
||||||
|
instance.requested_on = timezone.now().astimezone(pytz.utc)
|
||||||
instance.task_status = str(NUMBER['four'])
|
instance.task_status = str(NUMBER['four'])
|
||||||
instance.is_approved = False
|
instance.is_approved = False
|
||||||
instance.save()
|
instance.save()
|
||||||
@ -445,7 +449,10 @@ class StartTaskSerializer(serializers.ModelSerializer):
|
|||||||
""" remaining time to complete task"""
|
""" remaining time to complete task"""
|
||||||
due_date = datetime.combine(obj.due_date, datetime.max.time())
|
due_date = datetime.combine(obj.due_date, datetime.max.time())
|
||||||
# fetch real time
|
# fetch real time
|
||||||
real_datetime = real_time()
|
# real_datetime = real_time()
|
||||||
|
# new code
|
||||||
|
due_date = due_date.astimezone(pytz.utc)
|
||||||
|
real_datetime = timezone.now().astimezone(pytz.utc)
|
||||||
# Perform the subtraction
|
# Perform the subtraction
|
||||||
if due_date > real_datetime:
|
if due_date > real_datetime:
|
||||||
time_difference = due_date - real_datetime
|
time_difference = due_date - real_datetime
|
||||||
|
|||||||
Reference in New Issue
Block a user