Skip to content

Commit f973730

Browse files
committed
💿 Correction des acteurs digitaux (#1761)
* Fix digital acteurs * WIP
1 parent 40432b3 commit f973730

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

jinja2/qfdmo/carte/_digital_results.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ <h5 class="fr-text--xl fr-text--bold fr-mb-0">{{ adresse.libelle }}</h5>
2525
</p>
2626
</div>
2727
{% endfor %}
28-
{% if acteurs.count() == 0 %}
28+
{% if acteurs|length == 0 %}
2929
<p class="qf-italic">
3030
Aucune solution en ligne n'a été trouvée pour votre recherche.
3131
</p>

qfdmo/models/acteur.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,20 @@ def with_bonus(self):
260260
return self.annotate(bonus=Exists(bonus_label_qualite))
261261

262262
def digital(self):
263-
return (
263+
# 1. Get ordered primary keys
264+
# List here ensures queryset is not re-evaluated, causing
265+
# a re-ordering and key error in the return below
266+
pks = list(
264267
self.filter(acteur_type__code=DIGITAL_ACTEUR_CODE)
265268
.annotate(min_action_order=Min("proposition_services__action__order"))
269+
.values("min_action_order", "pk")
266270
.order_by("min_action_order", "?")
271+
.values_list("pk", flat=True)[:100]
267272
)
273+
# 2. Fetch digital acteurs and preserver ordering.
274+
ordered_pks = {pk: index for index, pk in enumerate(pks)}
275+
instances = list(self.filter(pk__in=pks))
276+
return sorted(instances, key=lambda x: ordered_pks[x.pk])
268277

269278
def physical(self):
270279
return self.exclude(acteur_type__code=DIGITAL_ACTEUR_CODE)

qfdmo/views/adresses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def get_context_data(self, **kwargs):
217217
acteurs = self._acteurs_from_sous_categorie_objet_and_actions()
218218

219219
if self.get_data_from_request_or_bounded_form("digital") == "1":
220-
acteurs = acteurs.digital()[:100]
220+
acteurs = acteurs.digital()
221221
else:
222222
bbox, acteurs = self._bbox_and_acteurs_from_location_or_epci(acteurs)
223223
acteurs = acteurs[: self._get_max_displayed_acteurs()]

0 commit comments

Comments
 (0)