Skip to content

Commit

Permalink
job_seekers_views: refactor the block's exit
Browse files Browse the repository at this point in the history
We introduce a `get_exit_url`, similar to `get_next_url` but for getting
the URL of the step *after* the block.
Depending on the tunnel, the output is different.
  • Loading branch information
EwenKorr committed Jan 23, 2025
1 parent 93f028b commit deba229
Showing 1 changed file with 28 additions and 38 deletions.
66 changes: 28 additions & 38 deletions itou/www/job_seekers_views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,27 @@ def setup(self, request, *args, hire_process=False, **kwargs):
and self.company == request.current_organization
)

def redirect_to_check_infos(self, job_seeker_public_id):
view_name = (
"job_seekers_views:check_job_seeker_info_for_hire"
if self.hire_process
else "job_seekers_views:check_job_seeker_info"
)
return HttpResponseRedirect(
reverse(view_name, kwargs={"company_pk": self.company.pk, "job_seeker_public_id": job_seeker_public_id})
)
def get_exit_url(self, job_seeker_public_id, created=False):
if self.is_gps:
return reverse("gps:my_groups")

kwargs = {"company_pk": self.company.pk, "job_seeker_public_id": job_seeker_public_id}
if created and self.hire_process:
# The job seeker was just created, we don't need to check info if we are hiring
if self.company.kind == CompanyKind.GEIQ:
view_name = "apply:geiq_eligibility_for_hire"
else:
view_name = "apply:eligibility_for_hire"
elif self.hire_process:
# Hiring a job seeker that was found but not created: we check info
view_name = "job_seekers_views:check_job_seeker_info_for_hire"
elif created:
# We created a job seeker, and we apply for them
view_name = "apply:application_jobs"
else:
# We found a job seeker to apply for, so we check their info
view_name = "job_seekers_views:check_job_seeker_info"
return reverse(view_name, kwargs=kwargs)

def get_context_data(self, **kwargs):
return super().get_context_data(**kwargs) | {
Expand Down Expand Up @@ -363,7 +375,7 @@ def post(self, request, *args, **kwargs):
# TODO(ewen): check_job_seeker_info doesn't use the session yet,
# so we delete the session here.
self.job_seeker_session.delete()
return self.redirect_to_check_infos(self.job_seeker.public_id)
return HttpResponseRedirect(self.get_exit_url(self.job_seeker.public_id))
else:
next_url = reverse(
"job_seekers_views:check_job_seeker_info",
Expand Down Expand Up @@ -417,9 +429,7 @@ def post(self, request, *args, **kwargs):
FollowUpGroup.objects.follow_beneficiary(
beneficiary=job_seeker, user=request.user, is_referent=True
)
return HttpResponseRedirect(reverse("gps:my_groups"))
else:
return self.redirect_to_check_infos(job_seeker.public_id)
return HttpResponseRedirect(self.get_exit_url(job_seeker.public_id))

context = {
# Ask the sender to confirm the NIR we found is associated to the correct user
Expand Down Expand Up @@ -488,7 +498,7 @@ def post(self, request, *args, **kwargs):
# The email we found is correct
if self.form.data.get("confirm"):
if not can_add_nir:
return self.redirect_to_check_infos(job_seeker.public_id)
return HttpResponseRedirect(self.get_exit_url(job_seeker.public_id))

try:
job_seeker.jobseeker_profile.nir = nir
Expand All @@ -509,9 +519,7 @@ def post(self, request, *args, **kwargs):
FollowUpGroup.objects.follow_beneficiary(
beneficiary=job_seeker, user=request.user, is_referent=True
)
return HttpResponseRedirect(reverse("gps:my_groups"))
else:
return self.redirect_to_check_infos(job_seeker.public_id)
return HttpResponseRedirect(self.get_exit_url(job_seeker.public_id))

return self.render_to_response(
self.get_context_data(**kwargs)
Expand Down Expand Up @@ -756,24 +764,6 @@ def setup(self, request, *args, **kwargs):
**self._get_profile_data_from_session(),
)

def get_next_url(self):
if self.is_gps:
return reverse("gps:my_groups")

kwargs = {"company_pk": self.company.pk, "job_seeker_public_id": self.profile.user.public_id}
if self.hire_process:
if self.company.kind == CompanyKind.GEIQ:
view_name = "apply:geiq_eligibility_for_hire"
else:
view_name = "apply:eligibility_for_hire"
else:
view_name = self.next_apply_url

return reverse(
view_name,
kwargs=kwargs,
)

def post(self, request, *args, **kwargs):
try:
with transaction.atomic():
Expand All @@ -797,7 +787,7 @@ def post(self, request, *args, **kwargs):
user.save()

self.job_seeker_session.delete()
url = self.get_next_url()
url = self.get_exit_url(self.profile.user.public_id, created=True)

if self.is_gps:
FollowUpGroup.objects.follow_beneficiary(beneficiary=user, user=request.user, is_referent=True)
Expand Down Expand Up @@ -1112,11 +1102,11 @@ def post(self, request, *args, **kwargs):
)
else:
self.profile.save()
url = self.get_next_url()
url = self.get_exit_url()
self.job_seeker_session.delete()
return HttpResponseRedirect(url)

def get_next_url(self):
def get_exit_url(self):
return self.job_seeker_session.get("config").get("from_url")

def get_context_data(self, **kwargs):
Expand Down

0 comments on commit deba229

Please sign in to comment.