Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPS: Transformer la liste des bénéficiaires en tableau #5359

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 41 additions & 42 deletions itou/templates/gps/includes/memberships_results.html
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
{% load str_filters %}
{% load matomo %}

<section aria-labelledby="results" id="follow-up-groups-section">
<div aria-labelledby="results" id="follow-up-groups-section" class="mt-3 mt-md-4">
{% if not memberships_page %}
<div class="c-box my-3 my-md-4">
<div class="c-box">
<p class="mb-0">Aucun résultat.</p>
</div>
{% else %}
{% for membership in memberships_page %}
<div class="c-box c-box--results has-links-inside my-3 my-md-4 membership-card">
<div class="c-box--results__header">
<div class="c-box--results__summary">
<i class="ri-user-line" aria-hidden="true"></i>
<div>
<h3>{{ membership.follow_up_group.beneficiary.get_full_name }}</h3>
<span>{{ membership.follow_up_group.beneficiary.email }}</span>
</div>
</div>
</div>
<hr class="m-0">
<div class="c-box--results__body">
{% with membership.nb_members|add:"-1" as counter %}
<p class="mb-0">
{# djlint:off #}
{# Don't let djlint add a newline before the . or it will add a space after référent and . #}
Vous avez ajouté ce bénéficiaire le <strong>{{ membership.created_at|date:"d/m/Y" }}</strong>{% if membership.is_referent %} et êtes <strong>référent</strong>{% endif %}.{# djlint:on #}
{% if counter < 1 %}
Aucun autre professionnel que vous n'est intervenu auprès de ce bénéficiaire.
{% else %}
{{ counter }} {{ counter|pluralizefr:"autre professionnel est intervenu,autres professionnels sont intervenus" }} auprès de ce bénéficiaire.
{% endif %}
</p>
{% endwith %}
</div>
<div class="c-box--results__footer">
<div class="d-flex justify-content-md-end">
<a href="{% url 'gps:user_details' public_id=membership.follow_up_group.beneficiary.public_id %}?back_url={{ request.get_full_path|urlencode }}"
class="btn btn-primary btn-block btn-ico w-100 w-md-auto"
aria-label="Consulter la fiche de {{ membership.follow_up_group.beneficiary.get_full_name }}"
{% matomo_event "GPS_liste_groupes" "clic" "consulter_fiche_candidat" %}>
<i class="ri-eye-line ri-xl fw-medium" aria-hidden="true"></i>
<span>Consulter la fiche</span>
</a>
</div>
</div>
</div>
{% endfor %}
<div class="table-responsive">
<table class="table table-hover">
<caption class="visually-hidden">Liste des bénéficiaires</caption>
<thead>
<tr>
<th scope="col">Prénom Nom</th>
<th scope="col">Suivi depuis</th>
<th scope="col" aria-label="Référent ou référente">Référent⸱e</th>
<th scope="col" aria-label="Nombre d’intervenants">Nbr d’intervenants</th>
</tr>
</thead>
<tbody>
{% for membership in memberships_page %}
<tr>
<td>
<a href="{% url 'gps:user_details' public_id=membership.follow_up_group.beneficiary.public_id %}?back_url={{ request.get_full_path|urlencode }}"
class="btn-link"
aria-label="Consulter la fiche de {{ membership.follow_up_group.beneficiary.get_full_name }}"
{% matomo_event "GPS_liste_groupes" "clic" "consulter_fiche_candidat" %}>
{{ membership.follow_up_group.beneficiary.get_full_name }}
</a>
</td>
<td>{{ membership.created_at|date:"d/m/Y" }}</td>
<td>
{% if membership.is_referent %}
<span class="badge badge-xs rounded-pill bg-accent-03-lighter text-primary">vous êtes référent</span>
{% elif membership.follow_up_group.referent %}
{{ membership.follow_up_group.referent.0.member.get_full_name }}
{% else %}
<span class="badge badge-xs rounded-pill bg-danger-light text-warning">pas de référent</span>
{% endif %}
</td>
<td>{{ membership.nb_members }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

{% include "includes/pagination.html" with page=memberships_page boost=True boost_target="#follow-up-groups-section" boost_indicator="#follow-up-groups-section" %}

{% endif %}
</section>
</div>
6 changes: 3 additions & 3 deletions itou/templates/gps/my_groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% endblock %}

{% block title_content %}
<div class="d-flex flex-column flex-md-row gap-3 mb-3 mb-md-4 justify-content-md-between align-items-md-center">
<div class="d-flex flex-column flex-md-row gap-3 mb-3 mb-md-5 justify-content-md-between align-items-md-center">
<h1 class="m-0">Mes bénéficiaires</h1>
<div class="d-flex flex-column flex-md-row gap-md-3" role="group" aria-label="Actions sur les groupes de suivi">
<a href='{% tally_form_url form_id="w5kLqM" user_public_id=user.public_id user_first_name=user.first_name user_last_name=user.last_name %}&{% if request.current_organization %}&user_organization_uid={{ request.current_organization.uid }}&user_organization_name={{ request.current_organization.display_name }}{% endif %}'
Expand All @@ -36,7 +36,7 @@ <h1 class="m-0">Mes bénéficiaires</h1>


{% block content %}
<section class="s-secion" id="gps-my-groups">
<section class="s-section" id="gps-my-groups">
<div class="s-section__container container">
<div class="s-section__row row">
<div class="col-12">
Expand All @@ -57,8 +57,8 @@ <h1 class="m-0">Mes bénéficiaires</h1>
{% bootstrap_field filters_form.beneficiary wrapper_class="w-lg-400px" show_label=False %}
</form>
</div>
{% include "gps/includes/memberships_results.html" with memberships_page=memberships_page %}
</div>
<div class="col-12">{% include "gps/includes/memberships_results.html" with memberships_page=memberships_page %}</div>
</div>
</div>
</section>
Expand Down
12 changes: 9 additions & 3 deletions itou/www/gps/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import PermissionDenied
from django.db.models import Count
from django.db.models import Count, Prefetch
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse, reverse_lazy
Expand Down Expand Up @@ -30,14 +30,20 @@ def my_groups(request, template_name="gps/my_groups.html"):
.annotate(nb_members=Count("follow_up_group__members"))
.order_by("-created_at")
.select_related("follow_up_group", "follow_up_group__beneficiary", "member")
.prefetch_related("follow_up_group__members")
.prefetch_related(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je me dis qu'un assertSnapshotQueries sur la vue pourrait être bien du coup :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est ajouté

Prefetch(
"follow_up_group__memberships",
queryset=FollowUpGroupMembership.objects.filter(is_referent=True)[:1],
to_attr="referent",
),
)
)
filters_form = MembershipsFiltersForm(memberships_qs=memberships, data=request.GET or None)

if filters_form.is_valid():
memberships = filters_form.filter()

memberships_page = pager(memberships, request.GET.get("page"), items_per_page=10)
memberships_page = pager(memberships, request.GET.get("page"), items_per_page=50)

context = {
"back_url": reverse("dashboard:index"),
Expand Down
Loading
Loading