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

feat(Activités des structures): Adaptation de l'affichage des secteurs d'activités des structures #1517

Merged
merged 6 commits into from
Nov 20, 2024
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
8 changes: 6 additions & 2 deletions lemarche/siaes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,12 @@ def presta_type_display(self) -> str:
return "Intérim"
if self.kind == siae_constants.KIND_AI:
return "Mise à disposition du personnel"
if self.presta_type:
return choice_array_to_values(siae_constants.PRESTA_CHOICES, self.presta_type)
if self.activities.exists():
presta_types = set()
for activity in self.activities.all():
if activity.presta_type:
presta_types.update(activity.presta_type)
return choice_array_to_values(siae_constants.PRESTA_CHOICES, list(presta_types))
return ""

@property
Expand Down
11 changes: 11 additions & 0 deletions lemarche/static/itou_marche/itou_marche.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ ul.summary-grid-list {
}

.cmsfr-background-dark {

& h1,
h2,
h3,
Expand Down Expand Up @@ -198,6 +199,7 @@ ul.summary-grid-list {
width: 100%;
border: 0;
}

.autocomplete__menu {
/* Style DSFR pour le menu */
border: 1px solid #000091;
Expand All @@ -212,3 +214,12 @@ ul.summary-grid-list {
.bg-gray {
background-color: var(--g300);
}

span.fr-tag--green-emeraude,
p.fr-tag--green-emeraude {
--idle: transparent;
--hover: var(--background-action-low-green-emeraude-hover);
--active: var(--background-action-low-green-emeraude-active);
background-color: var(--background-action-low-green-emeraude);
color: var(--text-action-high-green-emeraude)
}
267 changes: 137 additions & 130 deletions lemarche/templates/siaes/_card_detail.html

Large diffs are not rendered by default.

87 changes: 41 additions & 46 deletions lemarche/templates/siaes/_card_search_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,36 @@
<div class="fr-col-1">
{% if siae.logo_url %}
<img src="{{ siae.logo_url }}"
class="fr-responsive-img"
alt="Logo de la structure {{ siae.name }}"
loading="lazy" />
class="fr-responsive-img"
alt="Logo de la structure {{ siae.name }}"
loading="lazy" />
{% else %}
<img src="{% static 'img/default-listing.png' %}"
class="fr-responsive-img"
alt="{{ siae.name }}"
loading="lazy" />
class="fr-responsive-img"
alt="{{ siae.name }}"
loading="lazy" />
{% endif %}
</div>
<div class="fr-col-10 fr-col-lg-7">
<h3 class="fr-card__title">
<a href="{% url 'siae:detail' siae.slug %}">{{ siae.name_display }}</a>
</h3>
<p class="fr-text--xs fr-mt-4v">
<span class="fr-badge fr-badge--blue-cumulus fr-mr-2v"
aria-describedby="tooltip-{{ siae.pk }}">{{ siae.kind }}</span> {{ siae.presta_type_display }}
<span class="fr-tooltip fr-placement"
id="tooltip-{{ siae.pk }}"
role="tooltip"
aria-hidden="true">{{ siae.get_kind_display }}</span>
</p>
</div>
<div class="fr-col-12 fr-col-lg-4">
<ul class="fr-tags-group lemarche--align-right">
<li>{% include "includes/_super_badge.html" with siae=siae %}</li>
{% if siae.is_qpv %}
<li>
<span class="fr-tag"
title="Quartier prioritaire de la politique de la ville">QPV</span>
title="Quartier prioritaire de la politique de la ville">QPV</span>
</li>
{% endif %}
{% if siae.is_zrr %}
Expand All @@ -39,63 +47,50 @@ <h3 class="fr-card__title">
<li>
{% if user.is_authenticated %}
{% if from_profile or siae.in_user_favorite_list_count_annotated %}
<button
id="favorite-remove-modal-btn"
class="fr-btn fr-btn--sm fr-btn--tertiary-no-outline fr-icon-star-fill"
x-data="favoriteItem"
x-init="initOptions('{{ siae.slug }}', '{{ siae.name_display|escapejs }}')"
@click="remove"
title="Dans votre liste d'achat">
Supprimer de votre liste d'achat
</button>
<button id="favorite-remove-modal-btn"
class="fr-btn fr-btn--sm fr-btn--tertiary-no-outline fr-icon-star-fill"
x-data="favoriteItem"
x-init="initOptions('{{ siae.slug }}', '{{ siae.name_display|escapejs }}')"
@click="remove"
title="Dans votre liste d'achat">Supprimer de votre liste d'achat</button>
{% else %}
<button
id="favorite-add-modal-btn"
class="fr-btn fr-btn--sm fr-btn--tertiary-no-outline fr-icon-star-line"
x-data="favoriteItem"
x-init="initOptions('{{ siae.slug }}', '{{ siae.name_display|escapejs }}')"
@click="add"
title="Ajouter à votre liste d'achat">
<button id="favorite-add-modal-btn"
class="fr-btn fr-btn--sm fr-btn--tertiary-no-outline fr-icon-star-line"
x-data="favoriteItem"
x-init="initOptions('{{ siae.slug }}', '{{ siae.name_display|escapejs }}')"
@click="add"
title="Ajouter à votre liste d'achat">
Ajouter à votre liste d'achat
</button>
{% endif %}
{% else %}
<button
id="favorite-modal-btn"
class="fr-btn fr-btn--tertiary-no-outline fr-icon-star-line"
data-fr-opened="false"
aria-controls="login_or_signup_modal"
data-next-params="{% url 'siae:search_results' %}?{{ current_search_query_escaped }}"
title="Ajouter à votre liste d'achat">
<button id="favorite-modal-btn"
class="fr-btn fr-btn--tertiary-no-outline fr-icon-star-line"
data-fr-opened="false"
aria-controls="login_or_signup_modal"
data-next-params="{% url 'siae:search_results' %}?{{ current_search_query_escaped }}"
title="Ajouter à votre liste d'achat">
Se connecter pour Ajouter à votre liste d'achat
</button>
{% endif %}
</li>
</ul>
</div>
</div>
<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12">
<span class="fr-tag">{{ siae.get_kind_display }}</span>
</div>
<div class="fr-col-12 fr-col-lg-6">
<p>
<span class="fr-icon-briefcase-line" aria-hidden="true"></span> {{ siae.presta_type_display }}
</p>
</div>
<div class="fr-col-12 fr-col-lg-6">
<p>{% siae_sectors_display siae display_max=3 current_search_query=current_search_query %}</p>
{% siae_sector_groups_display siae display_max=3 current_sector_groups=current_sector_groups %}
{% if user.is_authenticated and user.is_admin and not siae.user_count %}
<p class="fr-card__detail fr-icon-warning-fill fr-mt-3w">pas encore inscrite</p>
{% endif %}
</div>
</div>
<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12">
<p class="fr-m-0">
<div class="fr-col-12 fr-col-lg-6">
<p class="fr-m-0 fr-mt-4v">
<span class="fr-icon-map-pin-2-line" aria-hidden="true"></span>
{{ siae.city }}
<span class="fr-icon-road-map-line fr-ml-2w" aria-hidden="true"></span>
{{ siae.geo_range_pretty_display }}
</p>
{% if user.is_authenticated and user.is_admin and not siae.user_count %}
<p class="fr-card__detail fr-icon-warning-fill fr-mt-3w">pas encore inscrite</p>
{% endif %}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lemarche/templates/siaes/_siae_activity_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h4>{{ activity.sector_group }}</h4>
</ul>
<p>
<span class="fr-icon-briefcase-line" aria-hidden="true"></span>
<span class="fr-sr-only ">Type(s) de prestation :</span>
<span class="fr-sr-only">Type(s) de prestation :</span>
<span>{{ activity.presta_type_display }}</span>
</p>
<p>
Expand Down
49 changes: 22 additions & 27 deletions lemarche/templates/siaes/_siae_activity_content.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
{% load siae_sectors_display %}

<p class="h4 lh-sm">
{% if with_collapse %}
<a href="#collapseSiaeActiviyContent{{ activity.id }}" class="text-decoration-none has-collapse-caret collapsed" data-toggle="collapse">
{{ activity.sector_group }}
</a>
{% else %}
{{ activity.sector_group }}
{% endif %}
</p>

<div id="collapseSiaeActiviyContent{{ activity.id }}" class="{% if with_collapse %}pb-3 collapse{% endif %}">
<ul style="padding-left:1.5rem">
{% siae_sectors_display activity display_max=6 output_format='li' %}
</ul>

<p class="mb-0">
<i class="ri-briefcase-4-line mr-1"></i>
<span class="sr-only">Type(s) de prestation :</span>
<span>{{ activity.presta_type_display }}</span>
</p>
<p class="mb-0">
<i class="ri-map-2-line"></i>
<span class="sr-only">Intervient sur : {{ siae.geo_range_pretty_title }}</span>
<span>{{ siae.geo_range_pretty_display }}</span>
</p>
</div>
<section class="fr-accordion">
<h3 class="fr-accordion__title">
<button class="fr-accordion__btn"
aria-expanded="false"
aria-controls="accordion-activity-{{ activity.id }}">{{ activity.sector_group }}</button>
</h3>
<div class="fr-collapse" id="accordion-activity-{{ activity.id }}">
<ul>
{% siae_sectors_display activity display_max=6 output_format='li' %}
</ul>
<p class="fr-mt-4w">
<span class="fr-icon-briefcase-line" aria-hidden="true"></span>
<span class="fr-sr-only">Type(s) de prestation :</span>
<span>{{ activity.presta_type_display }}</span>
</p>
<p>
<span class="fr-icon-map-pin-2-line" aria-hidden="true"></span>
<span class="fr-sr-only">Intervient sur :</span>
<span>{{ activity.geo_range_pretty_display }}</span>
</p>
</div>
</section>
12 changes: 12 additions & 0 deletions lemarche/templates/utils/templatetags/siae_sectors_display.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ul class="fr-tags-group">
{% for sector_group in current_search_sector_groups %}
<li>
<span class="fr-tag fr-tag--green-emeraude fr-tag--sm">{{ sector_group }}</span>
</li>
{% endfor %}
{% for sector_group in sector_groups %}
<li>
<span class="fr-tag fr-tag--sm">{{ sector_group }}</span>
</li>
{% endfor %}
</ul>
41 changes: 41 additions & 0 deletions lemarche/utils/templatetags/siae_sectors_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,44 @@ def siae_sectors_display(object, display_max=5, current_search_query="", output_
return mark_safe("".join([f"<li>{elem_name}</li>" for elem_name in values]))
else: # "string"
return ", ".join(values)


@register.inclusion_tag("utils/templatetags/siae_sectors_display.html")
def siae_sector_groups_display(object, display_max=5, current_sector_groups=[]):
"""
Pretty rendering of M2M field SectorGroup for Siae.
"""

# to avoid duplicates and display current search values first
seen_slugs = set()

current_values = []
# Add sector groups from current_sector_groups if they are in object's activities
for sector_group in current_sector_groups:
if any(activity.sector_group.slug == sector_group.slug for activity in object.activities.all()):
if sector_group.slug not in seen_slugs:
current_values.append(sector_group.name)
seen_slugs.add(sector_group.slug)

values = []

# Add remaining sector groups from object's activities
for activity in object.activities.all():
if activity.sector_group.slug not in seen_slugs:
values.append(activity.sector_group.name)
seen_slugs.add(activity.sector_group.slug)

# alphabetical order here to avoid N+1 queries
values = sorted(values)

# filter number of displayed values
groups_count = len(seen_slugs)
if groups_count > display_max:
display_max_values = display_max - len(current_values)
if display_max_values > 0:
values = values[:display_max_values]
else:
values = []
values.append(f"+{groups_count-display_max}")

return {"current_search_sector_groups": sorted(current_values), "sector_groups": values}
Loading
Loading