diff --git a/qgis-app/plugins/templates/plugins/plugin_list_sort.html b/qgis-app/plugins/templates/plugins/plugin_list_sort.html index aa0cdae..9b88a5a 100644 --- a/qgis-app/plugins/templates/plugins/plugin_list_sort.html +++ b/qgis-app/plugins/templates/plugins/plugin_list_sort.html @@ -4,6 +4,7 @@ + @@ -24,20 +26,22 @@ \ No newline at end of file diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index acbe619..4ef36bb 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -836,18 +836,19 @@ def get_queryset(self): qs = self.get_filtered_queryset(qs) # Get the sort and order parameters from the URL (with default values) - sort_by = self.request.GET.get('sort', 'name') # Default sort by name - sort_order = self.request.GET.get('order', 'asc') # Default to ascending order - - # Determine the correct sorting direction - if sort_order == 'desc': - sort_by = '-' + sort_by # Prepend '-' to sort in descending order - - # Validate the sort field - if sort_by.lstrip('-') in ['average_vote', 'latest_version_date'] or self._is_valid_field(sort_by.lstrip('-')): - qs = qs.order_by(sort_by) - elif not qs.ordered: - qs = qs.order_by(Lower("name")) + sort_by = self.request.GET.get('sort', None) # Default sort by name + sort_order = self.request.GET.get('order', None) # Default to ascending order + + if sort_by and sort_order: + # Determine the correct sorting direction + if sort_order == 'desc': + sort_by = '-' + sort_by # Prepend '-' to sort in descending order + + # Validate the sort field + if sort_by.lstrip('-') in ['average_vote', 'latest_version_date'] or self._is_valid_field(sort_by.lstrip('-')): + qs = qs.order_by(sort_by) + elif not qs.ordered: + qs = qs.order_by(Lower("name")) return qs