Skip to content

Commit

Permalink
gps: Allow to register a new beneficiary
Browse files Browse the repository at this point in the history
  • Loading branch information
celine-m-s authored and tonial committed Jun 11, 2024
1 parent 51991ca commit 1c5df7a
Show file tree
Hide file tree
Showing 21 changed files with 790 additions and 143 deletions.
21 changes: 20 additions & 1 deletion itou/gps/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
from django.db import models
from django.db import models, transaction
from django.utils import timezone

from itou.users.models import User


class FollowUpGroupManager(models.Manager):
def follow_beneficiary(self, beneficiary, user, is_referent=False):
with transaction.atomic():
group, _ = FollowUpGroup.objects.get_or_create(beneficiary=beneficiary)

updated = FollowUpGroupMembership.objects.filter(member=user, follow_up_group=group).update(
is_active=True, is_referent=is_referent
)
if not updated:
FollowUpGroupMembership.objects.create(
follow_up_group=group,
member=user,
creator=user,
is_referent=is_referent,
)


class FollowUpGroup(models.Model):
created_at = models.DateTimeField(verbose_name="date de création", default=timezone.now)

objects = FollowUpGroupManager()

updated_at = models.DateTimeField(verbose_name="date de modification", auto_now=True)

beneficiary = models.OneToOneField(
Expand Down
33 changes: 33 additions & 0 deletions itou/static/js/gps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
htmx.onLoad((target) => {
// Verify this override when Select2 is updated.
// Overriding the noResults text is extraordinarily complicated.
// https://github.com/select2/select2/issues/3799
const searchUserInputField = $("#js-search-user-input")
const amdRequire = jQuery.fn.select2.amd.require;
const Translation = amdRequire("select2/translation");
const frTranslations = Translation.loadPath("./i18n/fr");
searchUserInputField.select2({
placeholder: 'Jean DUPONT',
escapeMarkup: function (markup) { return markup; },
language: {
...frTranslations.dict,
noResults: () => `
<div class="d-inline-flex w-100 mb-2">
<span class="text-muted d-block pe-1">Aucun résultat.</span>
<a href="${searchUserInputField.data('noResultsUrl')}" class="link">Enregistrer un nouveau bénéficiaire</a>
</div>
`,
},
});
searchUserInputField.on("select2:select", function (e) {
const submit_button = $("#join_group_form .btn-primary.disabled");
submit_button.attr("disabled", false);
submit_button.removeClass("disabled");
submit_button.attr("type", "submit"); // hack because button_forms.html don't allow easily to change it.
});
searchUserInputField.on("select2:unselect", function (e) {
const submit_button = $("#join_group_form .btn-primary");
submit_button.attr("disabled", true);
submit_button.addClass("disabled");
});
});
8 changes: 6 additions & 2 deletions itou/templates/apply/includes/_submit_title.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
Déclarer une embauche
{% endif %}
{% else %}
Enregistrer une candidature
{% if job_seeker %}pour {{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}{% endif %}
{% if is_gps %}
Enregistrer un nouveau bénéficaire
{% else %}
Enregistrer une candidature
{% if job_seeker %}pour {{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}{% endif %}
{% endif %}
{% endif %}
{% elif request.user.is_prescriber %}
Postuler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
{% extends "apply/submit/create_or_update_job_seeker/step_base.html" %}
{% load django_bootstrap5 %}

{% block progress_title %}État civil du candidat{% endblock %}
{% block step_title %}Quel est l’état civil du candidat ?{% endblock %}
{% block progress_title %}
État civil du
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
{% endblock %}
{% block step_title %}
Quel est l’état civil du
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
?
{% endblock %}

{% block form_content %}
<fieldset>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
{% extends "apply/submit/create_or_update_job_seeker/step_base.html" %}
{% load django_bootstrap5 %}

{% block progress_title %}Coordonnées du candidat{% endblock %}
{% block step_title %}Quelles sont les coordonnées du candidat ?{% endblock %}
{% block progress_title %}
Coordonnées du
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
{% endblock %}
{% block step_title %}
Quelles sont les coordonnées du
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
?
{% endblock %}

{% block form_content %}
<fieldset>
<legend class="visually-hidden">Coordonnées du candidat</legend>
<legend class="visually-hidden">
Coordonnées du
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
</legend>
{% bootstrap_field form.address_for_autocomplete %}
{% bootstrap_field form.address_line_1 %}
{% bootstrap_field form.address_line_2 %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
{% extends "apply/submit/create_or_update_job_seeker/step_base.html" %}
{% load django_bootstrap5 %}

{% block progress_title %}Situation du candidat{% endblock %}
{% block step_title %}Quelle est la situation du candidat ?{% endblock %}
{% block progress_title %}
Situation du
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
{% endblock %}
{% block step_title %}
Quelle est la situation du
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
?
{% endblock %}

{% block form_content %}
<fieldset>
<legend class="visually-hidden">Situation du candidat</legend>
<legend class="visually-hidden">
Situation du
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
</legend>
{% bootstrap_field form.education_level %}

{% bootstrap_field form.resourceless %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
{% else %}
Création
{% endif %}
du compte candidat {{ block.super }}
du compte
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
{{ block.super }}
{% endblock %}

{% block content_title %}
Expand All @@ -19,7 +25,12 @@ <h1>
{% else %}
Création
{% endif %}
du compte candidat
du compte
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
</h1>
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@
{% load buttons_form %}

{% block title %}
{% if update_job_seeker %}
Modification

{% if is_gps %}
Création du bénéficiaire
{% else %}
Création
{% if update_job_seeker %}
Modification
{% else %}
Création
{% endif %}
du compte candidat
{% endif %}
du compte candidat {{ block.super }}
{{ block.super }}
{% endblock %}

{% block content_title %}
<h1 class="my-5">
{% if update_job_seeker %}
Modification
{% if is_gps %}
Création du bénéficiaire
{% else %}
Création
{% if update_job_seeker %}
Modification
{% else %}
Création
{% endif %}
du compte candidat
{% endif %}
du compte candidat
</h1>
{% endblock %}

Expand All @@ -45,7 +55,11 @@ <h1 class="my-5">
{% if update_job_seeker %}
{% itou_buttons_form primary_label="Valider les informations" secondary_url=back_url reset_url=reset_url show_mandatory_fields_mention=False %}
{% else %}
{% itou_buttons_form primary_label="Créer le compte candidat" secondary_url=back_url reset_url=reset_url show_mandatory_fields_mention=False %}
{% if is_gps %}
{% itou_buttons_form primary_label="Créer et suivre le bénéficiaire" secondary_url=back_url reset_url=reset_url show_mandatory_fields_mention=False %}
{% else %}
{% itou_buttons_form primary_label="Créer le compte candidat" secondary_url=back_url reset_url=reset_url show_mandatory_fields_mention=False %}
{% endif %}
{% endif %}
</form>
</div>
Expand Down
12 changes: 10 additions & 2 deletions itou/templates/apply/submit_step_check_job_seeker_nir.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,20 @@ <h3 class="modal-title" id="nir-confirmation-label">Utilisateur trouvé</h3>
Le numéro {{ form.nir.value|format_nir }} est associé au compte de <b>{{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}</b>.
</p>
<p>
Si cette candidature n'est pas pour <b>{{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}</b>, cliquez sur « Ce n'est pas mon candidat » afin de modifier le numéro de sécurité sociale.
{% if is_gps %}
Si ce n'est pas le bénéficiaire que vous souhaitez suivre, cliquez sur « Suivre un autre bénéficiaire » afin de modifier le numéro de sécurité sociale.
{% else %}
Si cette candidature n'est pas pour <b>{{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}</b>, cliquez sur « Ce n'est pas mon candidat » afin de modifier le numéro de sécurité sociale.
{% endif %}
</p>
</div>
<div class="modal-footer">
{# Reload this page with a new form. #}
{% bootstrap_button "Ce n'est pas mon candidat" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{% if is_gps %}
{% bootstrap_button "Suivre un autre bénéficiaire" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{% else %}
{% bootstrap_button "Ce n'est pas mon candidat" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{% endif %}
{# Go to the next step. #}
{% bootstrap_button "Continuer" button_type="submit" button_class="btn btn-sm btn-primary" name="confirm" value="1" %}
</div>
Expand Down
43 changes: 29 additions & 14 deletions itou/templates/apply/submit_step_job_seeker.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,42 @@ <h3 class="modal-title" id="email-confirmation-label">Email existant</h3>
</p>
<p>
L'identité du candidat est une information clé pour la structure.
Si cette candidature n'est pas pour <b>{{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}</b>, cliquez sur
« Ce n'est pas mon candidat » afin d'enregistrer ses informations
personnelles.
{% if is_gps %}
Si vous ne souhaitez pas suivre <b>{{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}</b>, cliquez sur « Suivre un autre bénéficiaire » afin d'enregistrer ses informations personnelles.
{% else %}
Si cette candidature n'est pas pour <b>{{ job_seeker.get_full_name|mask_unless:can_view_personal_information }}</b>, cliquez sur
« Ce n'est pas mon candidat » afin d'enregistrer ses informations
personnelles.
{% endif %}
</p>
{% if can_add_nir %}
<p>
En cliquant sur « Continuer », <b>vous acceptez que le numéro de sécurité sociale {{ nir|format_nir }} soit associé à ce candidat.</b>
</p>
{% endif %}
</div>
<div class="modal-footer">
{# Reload this page with a new form. #}
En cliquant sur « Continuer », <b>vous acceptez que le numéro de sécurité sociale {{ nir|format_nir }} soit associé à ce
{% if is_gps %}
bénéficiaire
{% else %}
candidat
{% endif %}
.</b>
</p>
{% endif %}
</div>
<div class="modal-footer">

{# Reload this page with a new form. #}
{% if is_gps %}
{% bootstrap_button "Suivre un autre bénéficiaire" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{% else %}
{% bootstrap_button "Ce n'est pas mon candidat" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{# Go to the next step. #}
{% bootstrap_button "Continuer" button_type="submit" button_class="btn btn-sm btn-primary" name="confirm" value="1" %}
</div>
{% endif %}
{# Go to the next step. #}
{% bootstrap_button "Continuer" button_type="submit" button_class="btn btn-sm btn-primary" name="confirm" value="1" %}
</div>
</div>
</div>
{% endif %}
</form>
</div>
{% endif %}
</form>
{% endblock %}

{% block script %}
Expand Down
14 changes: 7 additions & 7 deletions itou/templates/dashboard/includes/gps_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<div class="px-3 px-lg-4 pt-3 pt-lg-4">
<ul class="list-unstyled mb-lg-5">
<li class="d-flex justify-content-between align-items-center mb-3">
<a href="{% url 'gps:my_groups' %}"
rel="noopener"
target="_blank"
aria-label="Gérer les utilisateurs suivis dans votre groupe."
class="btn-link btn-ico"
{% matomo_event "gps" "clic" "tdb_liste_beneficiaires" %}>
<a href="{% url 'gps:my_groups' %}" aria-label="Gérer les utilisateurs suivis dans votre groupe." class="btn-link btn-ico" {% matomo_event "gps" "clic" "tdb_liste_beneficiaires" %}>
<i class="ri-article-line ri-lg font-weight-normal align-self-start"></i>
<span>Visualiser les bénéficiaires</span>
<i class="ri-external-link-line font-weight-normal ms-2"></i>
</a>
</li>
<li class="d-flex justify-content-between align-items-center mb-3">
<a href="{% url 'gps:join_group' %}?back_url={% url 'dashboard:index' %}" aria-label="Créer ou rejoindre un groupe." class="btn-link btn-ico" {% matomo_event "gps" "clic" "tbd_ajout_groupe" %}>
<i class="ri-play-list-add-line ri-lg font-weight-normal align-self-start"></i>
<span>Ajouter un bénéficiaire</span>
</a>
</li>
</ul>
Expand Down
14 changes: 14 additions & 0 deletions itou/templates/gps/includes/confirm_modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div id="{{ id }}" class="modal fade" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">{{ title }}</h3>
</div>
<div class="modal-body">{{ body }}</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-outline-primary" data-bs-dismiss="modal">Retour</button>
<a href="{{ confirm_url }}" class="btn btn-sm {{ confirm_class }}">{{ confirm_text }}</a>
</div>
</div>
</div>
</div>
Loading

0 comments on commit 1c5df7a

Please sign in to comment.