Skip to content

Commit

Permalink
Use number from per_page_list for show more
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpirix committed Nov 20, 2023
1 parent 573590b commit 7a35e0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 5 additions & 3 deletions qgis-app/plugins/tests/test_plugin_list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.test import TestCase
from django.urls import reverse
from ..models import Plugin

class PluginsListViewTestCase(TestCase):
fixtures = [
Expand Down Expand Up @@ -32,17 +33,18 @@ 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)
self.assertTrue('per_page_list' in response.context)
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
Expand Down
14 changes: 13 additions & 1 deletion qgis-app/plugins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7a35e0b

Please sign in to comment.