Skip to content

Commit

Permalink
Sort the search result by download number
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Oct 3, 2024
1 parent 630be8d commit 0416d07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions qgis-app/custom_haystack_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ def build_form(self, form_kwargs=None):

def get_results(self):
"""
Fetches the results
Fetches the search results and sorts them in descending order based on the 'downloads' attribute.
If the 'downloads' attribute is not present or the object is None, it defaults to 0.
"""
return self.form.searchqueryset
results = self.form.searchqueryset
sort_by = 'downloads'
results = sorted(
results,
key=lambda x: int(
getattr(x.object, sort_by)
) if x.object is not None else 0,
reverse=True # Reverse the sort order
)
return results


urlpatterns = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% load i18n plugin_utils plugins_tagcloud thumbnail static%}
{% load local_timezone humanize %}

{% if object.package_name %}
<div class="
column
is-medium
Expand Down Expand Up @@ -111,4 +112,5 @@
</p>
</footer>
</div>
</div>
</div>
{% endif %}

0 comments on commit 0416d07

Please sign in to comment.