Skip to content

Commit

Permalink
www.apply: take advantage of jobseeker_valid_eligibility_diagnosis an…
Browse files Browse the repository at this point in the history
…notation

to prevent extra queries

jobseeker_eligibility_diagnosis could not be used because the
application eligibilit_diagnosis could be an expired diagnosis in the
case of accepted then cancelled applications.
  • Loading branch information
xavfernandez committed Oct 4, 2024
1 parent 050bfec commit dcae3a1
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 1,640 deletions.
18 changes: 14 additions & 4 deletions itou/job_applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ def with_accepted_at(self):
)
)

def with_jobseeker_eligibility_diagnosis(self):
def with_jobseeker_valid_eligibility_diagnosis(self):
"""
Gives the "eligibility_diagnosis" linked to the job application or if none is found
the last valid eligibility diagnosis for this job seeker and this SIAE
Gives the last valid eligibility diagnosis for this job seeker and this SIAE
"""
sub_query = Subquery(
(
Expand All @@ -240,7 +239,18 @@ def with_jobseeker_eligibility_diagnosis(self):
),
output_field=models.IntegerField(),
)
return self.annotate(jobseeker_eligibility_diagnosis=Coalesce(F("eligibility_diagnosis"), sub_query, None))
return self.annotate(jobseeker_valid_eligibility_diagnosis=sub_query)

def with_jobseeker_eligibility_diagnosis(self):
"""
Gives the "eligibility_diagnosis" linked to the job application or if none is found
the last valid eligibility diagnosis for this job seeker and this SIAE
"""
return self.with_jobseeker_valid_eligibility_diagnosis().annotate(
jobseeker_eligibility_diagnosis=Coalesce(
F("eligibility_diagnosis"), F("jobseeker_valid_eligibility_diagnosis")
)
)

def eligibility_validated(self):
return self.filter(
Expand Down
2 changes: 1 addition & 1 deletion itou/templates/apply/includes/list_card_body_company.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h3>
PASS IAE {{ approval.get_state_display|lower }}
</span>
{% else %}
{% if job_application.iae_eligibility_diagnosis_required %}
{% if not job_application.jobseeker_valid_eligibility_diagnosis %}
<span class="badge badge-xs rounded-pill bg-accent-02-lighter text-primary">
<i class="ri-error-warning-line" aria-hidden="true"></i>
Éligibilité IAE à valider
Expand Down
7 changes: 0 additions & 7 deletions itou/www/apply/views/list_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ def _add_administrative_criteria(job_applications):
job_application.preloaded_administrative_criteria_extra_nb = extra_nb


def _add_eligibility_diagnosis_required(job_applications):
for job_app in job_applications:
job_app.iae_eligibility_diagnosis_required = job_app.eligibility_diagnosis_by_siae_required()


@login_required
@user_passes_test(lambda u: u.is_job_seeker, login_url=reverse_lazy("search:employers_home"), redirect_field_name=None)
def list_for_job_seeker(request, template_name="apply/list_for_job_seeker.html"):
Expand Down Expand Up @@ -164,7 +159,6 @@ def list_prescriptions(request, template_name="apply/list_prescriptions.html"):
_add_pending_for_weeks(job_applications_page)
_add_user_can_view_personal_information(job_applications_page, request.user.can_view_personal_information)
_add_administrative_criteria(job_applications_page)
_add_eligibility_diagnosis_required(job_applications_page)

context = {
"title": title,
Expand Down Expand Up @@ -293,7 +287,6 @@ def list_for_siae(request, template_name="apply/list_for_siae.html"):
iae_company = company.kind in SIAE_WITH_CONVENTION_KINDS
if iae_company:
_add_administrative_criteria(job_applications_page)
_add_eligibility_diagnosis_required(job_applications_page)

context = {
"title": title,
Expand Down
Loading

0 comments on commit dcae3a1

Please sign in to comment.