Skip to content

Commit

Permalink
tmp: use url_add_query tag for GET parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenKorr committed Oct 15, 2024
1 parent f87d233 commit 0bbb5f5
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 54 deletions.
7 changes: 5 additions & 2 deletions itou/templates/companies/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load str_filters %}
{% load matomo %}
{% load markdownify %}
{% load url_add_query %}

{% block title %}{{ siae.display_name }} {{ block.super }}{% endblock %}

Expand Down Expand Up @@ -39,7 +40,8 @@ <h2 class="visually-hidden">Actions rapides</h2>
</div>
{% else %}
<div class="form-group col-12 col-lg-auto">
<a href="{% url 'apply:start' company_pk=siae.pk %}{% if job_seeker %}?job_seeker={{ job_seeker.public_id }}{% endif %}"
{% url 'apply:start' company_pk=siae.pk as apply_url %}
<a href="{% url_add_query apply_url job_seeker=job_seeker.public_id|default:"" %}"
class="btn btn-lg btn-white btn-block btn-ico"
{% matomo_event "candidature" "clic" "start_application" %}
aria-label="Postuler auprès de l'employeur inclusif {{ siae.display_name }}">
Expand Down Expand Up @@ -198,8 +200,9 @@ <h2 class="visually-hidden" id="metiers-title">Métiers de la structure</h2>
</div>
{% else %}
<div class="d-flex justify-content-end mt-3">
{% url 'apply:start' company_pk=siae.pk as apply_url %}
<a class="btn btn-primary btn-ico flex-grow-1 flex-lg-grow-0"
href="{% url 'apply:start' company_pk=siae.pk %}{% if job_seeker %}?job_seeker={{ job_seeker.public_id }}{% endif %}"
href="{% url_add_query apply_url job_seeker=job_seeker.public_id|default:"" %}"
{% matomo_event "candidature" "clic" "start_application" %}
aria-label="Postuler auprès de l'employeur inclusif {{ siae.display_name }}">
<i class="ri-draft-line"></i>
Expand Down
5 changes: 3 additions & 2 deletions itou/templates/companies/includes/_card_jobdescription.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load static %}
{% load matomo %}
{% load url_add_query %}

{% comment %} takes argument siae <Siae>{% endcomment %}
<div class="c-box c-box--results has-links-inside my-3 my-md-4">
Expand All @@ -10,7 +11,7 @@
<i class="ri-community-line fw-medium me-1" aria-hidden="true"></i>
<span class="fw-bold">{{ job_description.market_context_description | default:"Entreprise anonyme" }}</span>
{% else %}
<a href="{{ job_description.company.get_card_url }}?{% if job_seeker %}job_seeker={{ job_seeker.public_id }}&{% endif %}back_url={{ request.get_full_path|urlencode }}"
<a href="{% url_add_query job_description.company.get_card_url job_seeker=job_seeker.public_id|default:'' back_url=request.get_full_path %}"
class="btn-ico btn-link"
{% matomo_event "candidature" "clic" "clic-structure-fichedeposte" %}>
<i class="ri-community-line fw-medium" aria-hidden="true"></i>
Expand All @@ -31,7 +32,7 @@
<li class="list-group-item list-group-item-action">
<div class="d-flex flex-column flex-md-row justify-content-md-between">
<div class="order-2 order-md-1">
<a href="{{ job_description.get_absolute_url }}?{% if job_seeker %}job_seeker={{ job_seeker.public_id }}&{% endif %}back_url={{ request.get_full_path|urlencode }}"
<a href="{% url_add_query job_description.get_absolute_url job_seeker=job_seeker.public_id|default:'' back_url=request.get_full_path %}"
class="fw-bold text-decoration-none {% if job_description.is_external %}has-external-link{% else %}stretched-link{% endif %}"
{% if job_description.is_external %} {% matomo_event "candidature" "clic" "clic-card-fichedeposte-externe" %} rel="noopener" target="_blank" aria-label="Visiter l'offre sur le site d'origine" {% else %} {% matomo_event "candidature" "clic" "clic-card-fichedeposte" %} aria-label="Aller vers la description de ce poste" {% endif %}>
{{ job_description.display_name | capfirst }}
Expand Down
9 changes: 6 additions & 3 deletions itou/templates/companies/includes/_card_siae.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load matomo %}
{% load str_filters %}
{% load url_add_query %}

{% comment %} takes argument siae <Siae>{% endcomment %}
<div class="c-box c-box--results has-links-inside mb-3 mb-md-4">
Expand Down Expand Up @@ -51,7 +52,7 @@ <h3>{{ siae.display_name }}</h3>
</div>
{% else %}
<div>
<a href="{{ siae.get_card_url }}?{% if job_seeker %}job_seeker={{ job_seeker.public_id }}&{% endif %}back_url={{ request.get_full_path|urlencode }}"
<a href="{% url_add_query siae.get_card_url job_seeker=job_seeker.public_id|default:'' back_url=request.get_full_path %}"
class="btn btn-outline-primary btn-block w-100 w-md-auto white-space-nowrap"
{% matomo_event "candidature" "clic" "clic-structure" %}>Voir la fiche de l'entreprise</a>
</div>
Expand All @@ -77,8 +78,9 @@ <h3>{{ siae.display_name }}</h3>
<div class="c-box--results__body">
<div class="d-flex flex-column flex-md-row justify-content-md-between align-items-md-center">
<p class="mb-3 mb-md-0">Cette structure vous intéresse ?</p>
{% url 'apply:start' company_pk=siae.pk as apply_url %}
<a class="btn btn-ico btn-primary"
href="{% url 'apply:start' company_pk=siae.pk %}{% if job_seeker %}?job_seeker={{ job_seeker.public_id }}{% endif %}"
href="{% url_add_query apply_url job_seeker=job_seeker.public_id|default:'' %}"
{% matomo_event "candidature" "clic" "start_application" %}
aria-label="Postuler auprès de l'employeur inclusif {{ siae.display_name }}">
<i class="ri ri-draft-line" aria-hidden="true"></i>
Expand Down Expand Up @@ -153,8 +155,9 @@ <h3>{{ siae.display_name }}</h3>
<div class="c-box--results__footer">
<div class="d-flex flex-column flex-md-row justify-content-md-between align-items-md-center">
<p class="mb-3 mb-md-0">Cette structure vous intéresse ?</p>
{% url 'apply:start' company_pk=siae.pk as apply_url %}
<a class="btn btn-ico btn-primary"
href="{% url 'apply:start' company_pk=siae.pk %}{% if job_seeker %}?job_seeker={{ job_seeker.public_id }}{% endif %}"
href="{% url_add_query apply_url job_seeker=job_seeker.public_id|default:'' %}"
{% matomo_event "candidature" "clic" "start_application" %}
aria-label="Postuler auprès de l'employeur inclusif {{ siae.display_name }}">
<i class="ri ri-draft-line" aria-hidden="true"></i>
Expand Down
12 changes: 9 additions & 3 deletions itou/templates/companies/includes/_company_info.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% load url_add_query %}

<div class="c-box c-box--structure {{ extra_box_class|default:'' }}">
<div class="c-box--structure__summary" data-bs-toggle="collapse" data-bs-target="#collapseBoxStructure" aria-expanded="{{ show|default:False|yesno:'true,false' }}" aria-controls="collapseBoxStructure">
<i class="ri-community-line"></i>
Expand All @@ -22,9 +24,13 @@ <h3>{{ company.display_name }}</h3>
<a href="{% url 'apply:job_application_external_transfer_step_1_company_card' job_application_id=job_app_to_transfer company_pk=company.pk %}{% if back_url|default:"" %}?back_url={{ back_url|urlencode }}{% endif %}"
class="btn btn-secondary btn-block mt-4">Voir la fiche de l'entreprise</a>
{% else %}
<a href="{% url 'companies_views:card' siae_id=company.pk %}?{% if job_seeker|default:None %}job_seeker={{ job_seeker.public_id }}&{% endif %}{% if back_url|default:"" and not open_in_tab|default:False %}back_url={{ back_url|urlencode }}{% endif %}"
class="btn btn-secondary btn-block mt-4"
{% if open_in_tab|default:False %}target="_blank"{% endif %}>Voir la fiche de l'entreprise</a>
{% url 'companies_views:card' siae_id=company.pk as company_url %}
{% if back_url|default:'' and not open_in_tab|default:False %}
{% url_add_query company_url job_seeker=job_seeker.public_id|default:'' back_url=back_url as company_url_params %}
{% else %}
{% url_add_query company_url job_seeker=job_seeker.public_id|default:'' as company_url_params %}
{% endif %}
<a href="{{ company_url_params }}" class="btn btn-secondary btn-block mt-4" {% if open_in_tab|default:False %}target="_blank"{% endif %}>Voir la fiche de l'entreprise</a>
{% endif %}
</div>
</div>
3 changes: 2 additions & 1 deletion itou/templates/companies/includes/_siae_jobdescription.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load matomo %}
{% load url_add_query %}

<li class="list-group-item list-group-item-action">
<div class="d-flex align-items-center">
Expand All @@ -9,7 +10,7 @@
class="fw-bold stretched-link order-2 order-md-1">{{ job.display_name }}</a>

{% else %}
<a href="{{ job.get_absolute_url }}?{% if job_seeker %}job_seeker={{ job_seeker.public_id }}&{% endif %}back_url={% if back_url %}{{ back_url|urlencode }}{% else %}{{ request.get_full_path|urlencode }}{% endif %}"
<a href="{% url_add_query job.get_absolute_url job_seeker=job_seeker.public_id|default:"" back_url=back_url|default:request.get_full_path %}"
class="fw-bold stretched-link order-2 order-md-1"
{% matomo_event "candidature" "clic" "clic-metiers" %}>{{ job.display_name }}</a>
{% endif %}
Expand Down
4 changes: 3 additions & 1 deletion itou/templates/companies/job_description_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load format_filters %}
{% load str_filters %}
{% load matomo %}
{% load url_add_query %}

{% block title %}{{ job.display_name }} - {{ siae.display_name }} {{ block.super }}{% endblock %}

Expand Down Expand Up @@ -65,7 +66,8 @@ <h2 class="visually-hidden">Actions rapides</h2>
</div>
{% else %}
<div class="form-group col-12 col-lg-auto">
<a href="{% url "apply:start" company_pk=siae.pk %}?job_description_id={{ job.pk }}{% if job_seeker %}&job_seeker={{ job_seeker.public_id }}{% endif %}"
{% url "apply:start" company_pk=siae.pk as apply_url %}
<a href="{% url_add_query apply_url job_description_id=job.pk job_seeker=job_seeker.public_id|default:'' %}"
class="btn btn-lg btn-white btn-block btn-ico"
{% matomo_event "candidature" "clic" "start_application" %}
aria-label="Postuler auprès de l'employeur inclusif {{ siae.display_name }}">
Expand Down
4 changes: 3 additions & 1 deletion itou/templates/job_seekers_views/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% load static %}
{% load str_filters %}
{% load format_filters %}
{% load url_add_query %}

{% block title %}
Profil de {{ job_seeker.get_full_name|mask_unless:can_view_personal_information }} {{ block.super }}
Expand All @@ -11,7 +12,8 @@
{% block title_content %}
<div class="d-flex flex-column flex-md-row gap-3 mb-3 justify-content-md-between">
<h1 class="mb-0">Candidat : {{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}</h1>
<a href="{% url 'search:employers_results' %}?job_seeker={{ job_seeker.public_id }}" class="btn btn-lg btn-primary btn-ico">
{% url 'search:employers_results' as search_url %}
<a href="{% url_add_query search_url job_seeker=job_seeker.public_id %}" class="btn btn-lg btn-primary btn-ico">
<i class="ri-draft-line fw-medium" aria-hidden="true"></i>
<span>Postuler pour ce candidat</span>
</a>
Expand Down
6 changes: 4 additions & 2 deletions itou/templates/job_seekers_views/includes/list_results.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% load static %}
{% load str_filters %}
{% load url_add_query %}

<section aria-labelledby="job-seekers-list-count" id="job-seekers-section">
{% if not page_obj %}
Expand Down Expand Up @@ -34,8 +35,9 @@
<td>{{ job_seeker.job_applications_nb }}</td>
<td>{{ job_seeker.last_updated_at|date:"d/m/Y" }}</td>
<td class="text-end w-50px">
<a class="btn btn-sm btn-link btn-ico-only" aria-label="Postuler pour ce candidat" href="{% url "search:employers_results" %}?job_seeker={{ job_seeker.public_id }}">
<i class="ri-draft-line" aria-hidden="true" data-bs-toggle="tooltip" title="Postuler"></i>
{% url "search:employers_results" as search_url %}
<a class="btn btn-sm btn-link btn-ico-only" aria-label="Postuler pour ce candidat" href="{% url_add_query search_url job_seeker=job_seeker.public_id %}">
<i class="ri-draft-line" aria-hidden="true" data-bs-toggle="tooltip" title="Postuler pour ce candidat"></i>
</a>
</td>
</tr>
Expand Down
3 changes: 2 additions & 1 deletion itou/templates/search/includes/siaes_search_content.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load url_add_query %}
<section class="s-section">
<div class="s-section__container container">
<div class="s-section__row row">
Expand All @@ -7,7 +8,7 @@
<div class="col-12">
{% include "search/includes/siaes_search_subtitle.html" %}
<div class="d-block w-100">
<form hx-get="{{ request.path }}{% if job_seeker %}?job_seeker={{ job_seeker.public_id }}{% endif %}"
<form hx-get="{% url_add_query request.path job_seeker=job_seeker.public_id|default:'' %}"
hx-trigger="change delay:.5s"
hx-include="#id_city"
hx-indicator="#job-search-results"
Expand Down
8 changes: 5 additions & 3 deletions itou/utils/templatetags/url_add_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ def url_add_query(url, **kwargs):
"""
parsed = urlsplit(url)
querystring = QueryDict(parsed.query, mutable=True)
for item in kwargs:
# Remove params with None or "" values
cleaned_kwargs = {k: v for k, v in kwargs.items() if v is not None and v != ""}
for item in cleaned_kwargs:
if item in querystring:
querystring.pop(item)
querystring.update(kwargs)
return urlunsplit(parsed._replace(query=querystring.urlencode()))
querystring.update(cleaned_kwargs)
return urlunsplit(parsed._replace(query=querystring.urlencode("/")))
11 changes: 7 additions & 4 deletions itou/www/apply/views/submit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from itou.utils.apis.exceptions import AddressLookupError
from itou.utils.emails import redact_email_address
from itou.utils.session import SessionNamespace, SessionNamespaceRequiredMixin
from itou.utils.urls import add_url_params
from itou.www.apply.forms import (
ApplicationJobsForm,
CheckJobSeekerInfoForm,
Expand Down Expand Up @@ -279,11 +280,13 @@ def get(self, request, *args, **kwargs):
job_seeker, _, _ = _check_apply_for_job_seeker(self.request)
if job_seeker:
return HttpResponseRedirect(
reverse(
"apply:application_jobs",
kwargs={"company_pk": self.company.pk, "job_seeker_public_id": job_seeker.public_id},
add_url_params(
reverse(
"apply:application_jobs",
kwargs={"company_pk": self.company.pk, "job_seeker_public_id": job_seeker.public_id},
),
{"job_description_id": job_description_id},
)
+ (f"?job_description_id={job_description_id}" if job_description_id else "")
)

# Warn message if prescriber's authorization is pending
Expand Down
10 changes: 10 additions & 0 deletions tests/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@ def test_url_add_query(self):
expected = "?page=1"
assert out == expected

# Empty or None parameters
context = {"url": "/company/10/card"}
template_empty = Template("{% load url_add_query %}{% url_add_query url job_seeker=job_seeker|default:'' %}")
out_empty = template_empty.render(Context(context))
template_none = Template("{% load url_add_query %}{% url_add_query url job_seeker=job_seeker|default:None %}")
out_none = template_none.render(Context(context))
expected = "/company/10/card"
assert out_empty == expected
assert out_none == expected

def test_redirection_url(self):
base_url = reverse("dashboard:index")
redirect_field_value = reverse("search:employers_home")
Expand Down
9 changes: 5 additions & 4 deletions tests/www/apply/test_submit_from_job_seekers_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.template.defaultfilters import urlencode
from urllib.parse import quote

from django.urls import reverse
from pytest_django.asserts import assertContains

Expand Down Expand Up @@ -81,7 +82,7 @@ def test_apply_as_prescriber(self, client):
# Has link to company card with job_seeker public_id
company_url_with_job_seeker_id = (
f"{guerande_company.get_card_url()}?job_seeker={job_seeker.public_id}"
f"&back_url={urlencode(response.wsgi_request.get_full_path())}"
f"&amp;back_url={quote(response.wsgi_request.get_full_path())}"
)
assertContains(
response,
Expand Down Expand Up @@ -236,7 +237,7 @@ def test_apply_as_prescriber_without_seeing_personal_info(self, client):
# Has link to company card with job_seeker public_id
company_url_with_job_seeker_id = (
f"{guerande_company.get_card_url()}?job_seeker={job_seeker.public_id}"
f"&back_url={urlencode(response.wsgi_request.get_full_path())}"
f"&amp;back_url={quote(response.wsgi_request.get_full_path())}"
)
assertContains(
response,
Expand Down Expand Up @@ -408,7 +409,7 @@ def test_apply_as_company(self, client):
# Has link to company card with job_seeker public_id
company_url_with_job_seeker_id = (
f"{other_company.get_card_url()}?job_seeker={job_seeker.public_id}"
f"&back_url={urlencode(response.wsgi_request.get_full_path())}"
f"&amp;back_url={quote(response.wsgi_request.get_full_path())}"
)
assertContains(
response,
Expand Down
Loading

0 comments on commit 0bbb5f5

Please sign in to comment.