Skip to content

Commit 774b1c7

Browse files
authored
set f= in next/prev links (#2175) (#2201)
1 parent bf7c6ca commit 774b1c7

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

pygeoapi/api/itemtypes.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,19 +616,26 @@ def get_collection_items(
616616
if offset > 0:
617617
prev_link = True
618618

619+
print(request.format)
619620
if prev_link:
620621
prev = max(0, offset - limit)
622+
url = f'{uri}?offset={prev}{serialized_query_params}'
623+
if request.format is not None:
624+
url = f'{uri}?f={request.format}&offset={prev}{serialized_query_params}' # noqa
625+
621626
content['links'].append(
622627
{
623628
'type': 'application/geo+json',
624629
'rel': 'prev',
625630
'title': l10n.translate('Items (prev)', request.locale),
626-
'href': f'{uri}?offset={prev}{serialized_query_params}'
631+
'href': url
627632
})
628633

629634
if next_link:
630635
next_ = offset + limit
631636
next_href = f'{uri}?offset={next_}{serialized_query_params}'
637+
if request.format is not None:
638+
next_href = f'{uri}?f={request.format}&offset={next_}{serialized_query_params}' # noqa
632639
content['links'].append(
633640
{
634641
'type': 'application/geo+json',

tests/api/test_itemtypes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ def test_get_collection_items(config, api_):
285285
assert '/collections/obs/items?f=csv&limit=1&bbox=-180,-90,180,90' \
286286
in links[3]['href']
287287
assert links[3]['rel'] == 'alternate'
288-
assert '/collections/obs/items?offset=0&limit=1&bbox=-180,-90,180,90' \
289-
in links[4]['href']
288+
assert '/collections/obs/items?offset=0&limit=1&bbox=-180,-90,180,90' in links[4]['href'] # noqa
290289
assert links[4]['rel'] == 'prev'
291290
assert '/collections/obs' in links[5]['href']
292291
assert links[4]['rel'] == 'prev'

0 commit comments

Comments
 (0)