This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial /api/export-mapbox/Locations.geojson API, refs #285
- Loading branch information
Showing
6 changed files
with
117 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_mapbox_export(client, ten_locations): | ||
response = client.get("/api/export-mapbox/Locations.geojson") | ||
joined = b"".join(response.streaming_content) | ||
assert json.loads(joined) == { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"id": location.public_id, | ||
"name": location.name, | ||
"location_type": "Hospital / Clinic", | ||
"website": None, | ||
"address": None, | ||
"hours": None, | ||
"public_notes": None, | ||
}, | ||
"geometry": {"type": "Point", "coordinates": [40.0, 30.0]}, | ||
} | ||
for location in ten_locations | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def keyset_pagination_iterator(input_queryset, batch_size=500, stop_after=None): | ||
all_queryset = input_queryset.order_by("pk") | ||
last_pk = None | ||
i = 0 | ||
while True: | ||
queryset = all_queryset | ||
if last_pk is not None: | ||
queryset = all_queryset.filter(pk__gt=last_pk) | ||
queryset = queryset[:batch_size] | ||
for row in queryset: | ||
last_pk = row.pk | ||
yield row | ||
i += 1 | ||
if stop_after and i >= stop_after: | ||
return | ||
if not queryset: | ||
break |