Fixed error in timezone

This commit is contained in:
uttamthummala 2023-10-20 19:33:13 +05:30
parent 4734834ad5
commit 9e95da5e03
4 changed files with 13 additions and 9 deletions

View File

@ -4,6 +4,7 @@ from rest_framework.decorators import api_view
from .serializers import * from .serializers import *
from .utils import * from .utils import *
import pytz
@api_view(['POST']) @api_view(['POST'])
@ -124,7 +125,10 @@ def updateDeadline(request, id, email, user_type):
opening.deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z') opening.deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z')
opening.changed_by = get_object_or_404(User, id=id) opening.changed_by = get_object_or_404(User, id=id)
opening.save() opening.save()
deadline=opening.deadline_datetime.strftime('%Y-%m-%d %H:%M:%S') deadline=opening.deadline_datetime
itz=pytz.timezone('Asia/Kolkata')
deadline=deadline.astimezone(itz)
deadline=deadline.strftime('%Y-%m-%d %H:%M:%S')
send_opening_to_notifications_service(id=opening.id,name=opening.company_name,deadline=deadline,role=opening.designation) send_opening_to_notifications_service(id=opening.id,name=opening.company_name,deadline=deadline,role=opening.designation)
return Response({'action': "Update Deadline", 'message': "Deadline Updated"}, return Response({'action': "Update Deadline", 'message': "Deadline Updated"},
status=status.HTTP_200_OK) status=status.HTTP_200_OK)
@ -151,7 +155,7 @@ def updateOfferAccepted(request, id, email, user_type):
if DEADLINE_DATETIME in data: if DEADLINE_DATETIME in data:
deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z') deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z')
else: else:
deadline_datetime = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) + datetime.timedelta(days=2) deadline_datetime = timezone.localtime(timezone.now()).replace(hour=0, minute=0, second=0, microsecond=0) + datetime.timedelta(days=2)
if opening_type == "Internship": if opening_type == "Internship":
opening = get_object_or_404(Internship, pk=data[OPENING_ID]) opening = get_object_or_404(Internship, pk=data[OPENING_ID])
else: else:

View File

@ -109,7 +109,7 @@ def getDashboard(request, id, email, user_type):
placementsdata = PlacementSerializerForStudent(filtered_placements, many=True).data placementsdata = PlacementSerializerForStudent(filtered_placements, many=True).data
placementApplications = PlacementApplication.objects.filter(student_id=id) placementApplications = PlacementApplication.objects.filter(student_id=id).order_by('-updated_at')
placementApplications = PlacementApplicationSerializer(placementApplications, many=True).data placementApplications = PlacementApplicationSerializer(placementApplications, many=True).data
internships = Internship.objects.filter(allowed_batch__contains=[studentDetails.batch], internships = Internship.objects.filter(allowed_batch__contains=[studentDetails.batch],
allowed_branch__contains=[studentDetails.branch], allowed_branch__contains=[studentDetails.branch],
@ -119,7 +119,7 @@ def getDashboard(request, id, email, user_type):
filtered_internships = internship_eligibility_filters(studentDetails, internships) filtered_internships = internship_eligibility_filters(studentDetails, internships)
internshipsdata = InternshipSerializerForStudent(filtered_internships, many=True).data internshipsdata = InternshipSerializerForStudent(filtered_internships, many=True).data
internshipApplications = InternshipApplication.objects.filter(student_id=id) internshipApplications = InternshipApplication.objects.filter(student_id=id).order_by('-updated_at')
internshipApplications = InternshipApplicationSerializer(internshipApplications, many=True).data internshipApplications = InternshipApplicationSerializer(internshipApplications, many=True).data
return Response( return Response(
{'action': "Get Dashboard - Student", 'message': "Data Found", "placements": placementsdata, {'action': "Get Dashboard - Student", 'message': "Data Found", "placements": placementsdata,

View File

@ -721,7 +721,7 @@ class AdminView(APITestCase):
self.assertEqual(Placement.objects.get( self.assertEqual(Placement.objects.get(
id=self.placement1.id).offer_accepted, True) id=self.placement1.id).offer_accepted, True)
self.assertEqual(Placement.objects.get( self.assertEqual(Placement.objects.get(
id=self.placement1.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=2)) id=self.placement1.id).deadline_datetime, timezone.localtime(timezone.now()).replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=2))
def test_offerAccepted_withDeadline(self): def test_offerAccepted_withDeadline(self):
url = reverse("Update Offer Accepted") url = reverse("Update Offer Accepted")
@ -729,7 +729,7 @@ class AdminView(APITestCase):
"opening_type": "Placement", "opening_type": "Placement",
"opening_id": self.placement3.id, "opening_id": self.placement3.id,
"offer_accepted": "true", "offer_accepted": "true",
"deadline_datetime": (timezone.now().replace( "deadline_datetime": (timezone.localtime(timezone.now()).replace(
hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z') hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S %z')
} }
self.admin.user_type = ["s_admin"] self.admin.user_type = ["s_admin"]
@ -739,7 +739,7 @@ class AdminView(APITestCase):
data), content_type='application/json') data), content_type='application/json')
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(Placement.objects.get( self.assertEqual(Placement.objects.get(
id=self.placement3.id).deadline_datetime, timezone.now().replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1)) id=self.placement3.id).deadline_datetime, timezone.localtime(timezone.now()).replace(hour=0, minute=0, second=0, microsecond=0)+timezone.timedelta(days=1))
self.assertEqual(response.data['message'], 'Offer Accepted Updated') self.assertEqual(response.data['message'], 'Offer Accepted Updated')
def test_offerAccepted_wrongOpening(self): def test_offerAccepted_wrongOpening(self):

View File

@ -481,11 +481,11 @@ def get_eligible_emails(opening_id, opening_type=PLACEMENT):
emails.append(student_user.email) emails.append(student_user.email)
except Exception as e: except Exception as e:
logger.warning('Utils - send_opening_notifications: For Loop' + str(e)) logger.warning('Utils - send_opening_notifications: For Loop' + str(e))
return False return False, []
return True, emails return True, emails
except: except:
logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info())) logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info()))
return False return False, []
def exception_email(opening): def exception_email(opening):
opening = opening.dict() opening = opening.dict()