DoesNotExists Error handled with messages.error for proper communication to user and remove misconception (#701)

This commit is contained in:
Rahul Vadisetty
2025-04-22 04:18:35 -04:00
committed by GitHub
parent c37cd20975
commit bd371d54e9

View File

@@ -1711,13 +1711,32 @@ def update_offer_letter_status(request):
"""
This method is used to update the offer letter status
"""
candidate_id = request.GET["candidate_id"]
status = request.GET["status"]
candidate = Candidate.objects.get(id=candidate_id)
candidate_id = request.GET.get("candidate_id")
status = request.GET.get("status")
candidate = None
if not candidate_id or not status:
messages.error(request, 'candidate or status is missing')
return redirect("/onboarding/candidates-view/")
if not status in ["not_sent", "sent", "accepted", "rejected", "joined"]:
messages.error(request, 'Please Pass valid status')
return redirect("/onboarding/candidates-view/")
try:
candidate = Candidate.objects.get(id=candidate_id)
except Candidate.DoesNotExist:
messages.error(request, 'Candidate not found')
return redirect("/onboarding/candidates-view/")
if status in ["not_sent", "sent", "accepted", "rejected", "joined"]:
candidate.offer_letter_status = status
candidate.save()
return HttpResponse("Success")
messages.success(request, 'Status of offer letter updated successfully')
url = '/onboarding/candidates-view/'
return HttpResponse(
f"""
<script>
window.location.href="{url}"
</script>
"""
)
@login_required