Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pygeoapi/api/itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,19 +616,26 @@ def get_collection_items(
if offset > 0:
prev_link = True

print(request.format)
if prev_link:
prev = max(0, offset - limit)
url = f'{uri}?offset={prev}{serialized_query_params}'
if request.format is not None:
url = f'{uri}?f={request.format}&offset={prev}{serialized_query_params}' # noqa

content['links'].append(
{
'type': 'application/geo+json',
'rel': 'prev',
'title': l10n.translate('Items (prev)', request.locale),
'href': f'{uri}?offset={prev}{serialized_query_params}'
'href': url
})

if next_link:
next_ = offset + limit
next_href = f'{uri}?offset={next_}{serialized_query_params}'
if request.format is not None:
next_href = f'{uri}?f={request.format}&offset={next_}{serialized_query_params}' # noqa
content['links'].append(
{
'type': 'application/geo+json',
Expand Down
3 changes: 1 addition & 2 deletions tests/api/test_itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ def test_get_collection_items(config, api_):
assert '/collections/obs/items?f=csv&limit=1&bbox=-180,-90,180,90' \
in links[3]['href']
assert links[3]['rel'] == 'alternate'
assert '/collections/obs/items?offset=0&limit=1&bbox=-180,-90,180,90' \
in links[4]['href']
assert '/collections/obs/items?offset=0&limit=1&bbox=-180,-90,180,90' in links[4]['href'] # noqa
assert links[4]['rel'] == 'prev'
assert '/collections/obs' in links[5]['href']
assert links[4]['rel'] == 'prev'
Expand Down