diff --git a/qgis-app/plugins/tests/test_plugin_list.py b/qgis-app/plugins/tests/test_plugin_list.py index d5984f1b..b17c0e17 100644 --- a/qgis-app/plugins/tests/test_plugin_list.py +++ b/qgis-app/plugins/tests/test_plugin_list.py @@ -1,5 +1,6 @@ from django.test import TestCase from django.urls import reverse +from ..models import Plugin class PluginsListViewTestCase(TestCase): fixtures = [ @@ -32,9 +33,9 @@ def test_plugins_list_pagination(self): self.assertTrue('show_more_items_number' in response.context) show_more_items_number = response.context['show_more_items_number'] - self.assertEqual(show_more_items_number, 70) + self.assertEqual(show_more_items_number, 50) - response = self.client.get(reverse('approved_plugins'), {'per_page': show_more_items_number}) + response = self.client.get(reverse('approved_plugins'), {'per_page': 110}) self.assertEqual(response.status_code, 200) self.assertTrue('current_sort_query' in response.context) self.assertTrue('current_querystring' in response.context) @@ -42,7 +43,8 @@ def test_plugins_list_pagination(self): self.assertTrue('show_more_items_number' in response.context) show_more_items_number = response.context['show_more_items_number'] - self.assertEqual(show_more_items_number, 120) + records_count = Plugin.approved_objects.count() + self.assertEqual(show_more_items_number, records_count + 1) def test_plugins_list_sorting(self): # Test the plugins list view with sorting diff --git a/qgis-app/plugins/views.py b/qgis-app/plugins/views.py index 17fdf40d..db666c18 100644 --- a/qgis-app/plugins/views.py +++ b/qgis-app/plugins/views.py @@ -606,7 +606,19 @@ def get_context_data(self, **kwargs): context["current_sort_query"] = self.get_sortstring() context["current_querystring"] = self.get_querystring() context["per_page_list"] = [20, 50, 75, 100] - context["show_more_items_number"] = context["paginator"].per_page + 50 + + try: + # Get the next value of per page from per_page_list + next_per_page_id = context["per_page_list"].index(context["paginator"].per_page) + 1 + next_per_page = context["per_page_list"][next_per_page_id] + except (ValueError, IndexError): + # If the 'per_page' value in the request parameter + # is not found in the 'per_page_list' or if the + # next index is out of range, set the 'next_per_page' + # value to a number greater than the total count + # of records. This action effectively disables the button." + next_per_page = context["paginator"].count + 1 + context["show_more_items_number"] = next_per_page return context def get_sortstring(self):