Skip to content

Commit

Permalink
fix reverse lookup (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored May 18, 2024
1 parent 5bd1c21 commit bbd1e28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 4 additions & 3 deletions django_oapif/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ class OgcAPIFeatureViewSet(OAPIFDescribeModelViewSetMixin, viewsets.ModelViewSet

filter_backends = [BboxFilterBackend]

# Allowing '.' and '-' in urls
lookup_value_regex = r"[\w.-]+"
# restrict o UUIDs lookup see https://www.django-rest-framework.org/api-guide/routers/
# lookup_value_regex = '[0-9a-f]{32}'
# lookup_value_converter = 'uuid'

# Metadata
metadata_class = OAPIFMetadata

def get_success_headers(self, data):
location = reverse.reverse(f"{self.basename}-detail", {"lookup": data[Model._meta.pk.column]})
location = reverse.reverse(f"{self.basename}-detail", args=[data[Model._meta.pk.column]])
headers = {"Location": location}
return headers

Expand Down
20 changes: 20 additions & 0 deletions tests/django_oapif_tests/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re

from django.contrib.auth.models import User
from django.core.management import call_command
Expand Down Expand Up @@ -97,3 +98,22 @@ def test_post_geometry_less_layer(self):
url = f"{collections_url}/{layer}/items"
post_to_items = self.client.post(url, data, format="json")
self.assertIn(post_to_items.status_code, (200, 201), (url, data, post_to_items.data))

def test_returned_id(self):
self.client.force_authenticate(user=self.demo_editor)
data = {
"geometry": {
"type": "Point",
"coordinates": [2508500.0, 1152000.0],
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:EPSG::2056"}},
},
"properties": {"field_str_0": "test123456"},
}

for layer in ("tests.point_2056_10fields",):
url = f"{collections_url}/{layer}/items"
post_to_items = self.client.post(url, data, format="json")
self.assertIn(post_to_items.status_code, (200, 201), (url, data, post_to_items.data))
location = post_to_items.headers["Location"]
print(location)
self.assertTrue(re.match(r"^.*[0-9a-f\-]{36}$", location))

0 comments on commit bbd1e28

Please sign in to comment.