mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
change method to get real time
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
"""Serializer of Guardian"""
|
||||
"""Third party Django app"""
|
||||
# third party imports
|
||||
import logging
|
||||
from rest_framework import serializers
|
||||
# Import Refresh token of jwt
|
||||
@ -7,7 +7,8 @@ from rest_framework_simplejwt.tokens import RefreshToken
|
||||
from django.db import transaction
|
||||
from django.contrib.auth.models import User
|
||||
from datetime import datetime, time
|
||||
"""Import Django app"""
|
||||
import pytz
|
||||
from django.utils import timezone
|
||||
# Import guardian's model,
|
||||
# Import junior's model,
|
||||
# Import account's model,
|
||||
@ -16,7 +17,7 @@ from datetime import datetime, time
|
||||
# Import messages from
|
||||
# base package,
|
||||
# Import some functions
|
||||
# from utils file"""
|
||||
# local imports
|
||||
from .models import Guardian, JuniorTask
|
||||
from account.models import UserProfile, UserEmailOtp, UserNotification
|
||||
from account.utils import generate_code
|
||||
@ -222,12 +223,9 @@ class TaskDetailsSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_remaining_time(self, obj):
|
||||
""" remaining time to complete task"""
|
||||
import pytz
|
||||
from django.utils import timezone
|
||||
due_date_datetime = datetime.combine(obj.due_date, datetime.max.time())
|
||||
# fetch real time
|
||||
# current_datetime = real_time()
|
||||
print(due_date_datetime.astimezone(pytz.utc), datetime.now(pytz.utc), timezone.now().astimezone(pytz.utc))
|
||||
# new code
|
||||
due_date_datetime = due_date_datetime.astimezone(pytz.utc)
|
||||
current_datetime = timezone.now().astimezone(pytz.utc)
|
||||
@ -260,7 +258,10 @@ class TaskDetailsjuniorSerializer(serializers.ModelSerializer):
|
||||
""" remaining time to complete task"""
|
||||
due_date_datetime = datetime.combine(obj.due_date, datetime.max.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
|
||||
if due_date_datetime > current_datetime:
|
||||
time_difference = due_date_datetime - current_datetime
|
||||
@ -377,7 +378,8 @@ class ApproveTaskSerializer(serializers.ModelSerializer):
|
||||
# update total task point
|
||||
junior_data.total_points = junior_data.total_points + instance.points
|
||||
# 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, {})
|
||||
else:
|
||||
# reject the task
|
||||
@ -386,7 +388,8 @@ class ApproveTaskSerializer(serializers.ModelSerializer):
|
||||
# update total task point
|
||||
junior_data.total_points = junior_data.total_points - instance.points
|
||||
# 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, {})
|
||||
instance.save()
|
||||
junior_data.save()
|
||||
|
||||
Reference in New Issue
Block a user