File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ <h5 class="fr-text--xl fr-text--bold fr-mb-0">{{ adresse.libelle }}</h5>
25
25
</ p >
26
26
</ div >
27
27
{% endfor %}
28
- {% if acteurs.count() == 0 %}
28
+ {% if acteurs|length == 0 %}
29
29
< p class ="qf-italic ">
30
30
Aucune solution en ligne n'a été trouvée pour votre recherche.
31
31
</ p >
Original file line number Diff line number Diff line change @@ -260,11 +260,20 @@ def with_bonus(self):
260
260
return self .annotate (bonus = Exists (bonus_label_qualite ))
261
261
262
262
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 (
264
267
self .filter (acteur_type__code = DIGITAL_ACTEUR_CODE )
265
268
.annotate (min_action_order = Min ("proposition_services__action__order" ))
269
+ .values ("min_action_order" , "pk" )
266
270
.order_by ("min_action_order" , "?" )
271
+ .values_list ("pk" , flat = True )[:100 ]
267
272
)
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 ])
268
277
269
278
def physical (self ):
270
279
return self .exclude (acteur_type__code = DIGITAL_ACTEUR_CODE )
Original file line number Diff line number Diff line change @@ -217,7 +217,7 @@ def get_context_data(self, **kwargs):
217
217
acteurs = self ._acteurs_from_sous_categorie_objet_and_actions ()
218
218
219
219
if self .get_data_from_request_or_bounded_form ("digital" ) == "1" :
220
- acteurs = acteurs .digital ()[: 100 ]
220
+ acteurs = acteurs .digital ()
221
221
else :
222
222
bbox , acteurs = self ._bbox_and_acteurs_from_location_or_epci (acteurs )
223
223
acteurs = acteurs [: self ._get_max_displayed_acteurs ()]
You can’t perform that action at this time.
0 commit comments