File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ def next_page(self) -> PageControl:
46
46
47
47
raise RuntimeError ("Next page not found." )
48
48
49
+ def resize (self , page_size : int ) -> Pagination :
50
+ self .page = (self .page - 1 ) * self .page_size // page_size + 1
51
+ self .page_size = page_size
52
+ return self
53
+
49
54
def add_pagination_urls (self , base_url : URL ) -> None :
50
55
# Previous pages
51
56
for p in range (self .page - min (self .max_page_controls , 3 ), self .page ):
Original file line number Diff line number Diff line change @@ -198,7 +198,7 @@ <h3 class="card-title">{{ model_view.name_plural }}</h3>
198
198
</ a >
199
199
< div class ="dropdown-menu ">
200
200
{% for page_size_option in model_view.page_size_options %}
201
- < a class ="dropdown-item " href ="{{ request.url.include_query_params(pageSize=page_size_option) }} ">
201
+ < a class ="dropdown-item " href ="{{ request.url.include_query_params(pageSize=page_size_option, page=pagination.resize(page_size_option).page ) }} ">
202
202
{{ page_size_option }} / Page
203
203
</ a >
204
204
{% endfor %}
Original file line number Diff line number Diff line change @@ -72,3 +72,14 @@ def test_multi_page_unequal_previous_and_next() -> None:
72
72
]
73
73
74
74
assert pagination .page_controls == page_controls
75
+
76
+
77
+ def test_resize_pagination () -> None :
78
+ pagination = Pagination (rows = [], page = 3 , page_size = 5 , count = 20 )
79
+ assert pagination .resize (100 ).page == 1
80
+
81
+ pagination = Pagination (rows = [], page = 3 , page_size = 5 , count = 20 )
82
+ assert pagination .resize (1 ).page == 11
83
+
84
+ pagination = Pagination (rows = [], page = 3 , page_size = 5 , count = 20 )
85
+ assert pagination .resize (8 ).page == 2
You can’t perform that action at this time.
0 commit comments