Skip to content

Commit 2d09b9e

Browse files
committed
fix collection prev and other links
1 parent 5a0ce8d commit 2d09b9e

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

77
Note: Minor version `0.X.0` update might break the API, It's recommended to pin `tipg` to minor version: `tipg>=0.1,<0.2`
88

9+
## [0.5.6] - 2023-12-19
10+
11+
- Fix collections `prev` links and collections html templates
12+
913
## [0.5.5] - 2023-12-19
1014

1115
- Fix `prev` offset value

tipg/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,5 +503,5 @@ def CollectionsParams(
503503
collections=collections_list,
504504
matched=matched,
505505
next=offset + returned if matched - returned > offset else None,
506-
prev=max(offset - returned, 0) if offset else None,
506+
prev=max(offset - limit, 0) if offset else None,
507507
)

tipg/factory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,8 @@ def collections(
449449
qp = dict(request.query_params)
450450
qp.pop("offset", None)
451451
query_params = QueryParams({**qp, "offset": prev_token})
452-
453452
url = self.url_for(request, "collections")
454-
if qp:
453+
if query_params:
455454
url += f"?{query_params}"
456455

457456
links.append(
@@ -830,7 +829,7 @@ async def items( # noqa: C901
830829
qp.pop("offset")
831830
query_params = QueryParams({**qp, "offset": prev_token})
832831
url = self.url_for(request, "items", collectionId=collection.id)
833-
if qp:
832+
if query_params:
834833
url += f"?{query_params}"
835834

836835
links.append(

tipg/templates/collections.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ <h1>Collections</h1>
8383
// paging
8484
//
8585
var offset = 0; // defaults
86-
var limit = 0;
86+
var limit = 10;
8787

8888
{% if "offset" in template.params %}
8989
offset = {{ template.params.offset }};
@@ -94,7 +94,7 @@ <h1>Collections</h1>
9494

9595
var current_page = 1;
9696
if (limit > 0) {
97-
current_page = (offset + limit)/limit;
97+
current_page = Math.ceil((offset + limit) / limit);
9898
}
9999
$("#current_page").html(current_page);
100100

0 commit comments

Comments
 (0)