Skip to content
Open
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
14 changes: 10 additions & 4 deletions django_oapif/collections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from typing import Any, NamedTuple, Optional, cast
from typing import Any, NamedTuple, Optional, Union, cast, get_args, get_origin

from django.contrib.gis.db.models import Extent, GeometryField
from django.contrib.gis.db.models.functions import AsGeoJSON, Transform
Expand Down Expand Up @@ -157,19 +157,22 @@ def get_collection_response(request: HttpRequest, collection: OAPIFCollectionEnt
itemType="feature",
links=[
OAPIFLink(
href=request.build_absolute_uri(f"{uri_prefix}{collection.id}"),
rel="self",
title="Collection",
type="application/json",
href=request.build_absolute_uri(f"{uri_prefix}{collection.id}"),
),
OAPIFLink(
href=request.build_absolute_uri(f"{uri_prefix}{collection.id}/schema"),
rel="http://www.opengis.net/def/rel/ogc/1.0/schema",
title="Collection schema",
type="application/json",
href=request.build_absolute_uri(f"{uri_prefix}{collection.id}/schema"),
),
OAPIFLink(
href=request.build_absolute_uri(f"{uri_prefix}{collection.id}/items"),
rel="items",
title="Collection items",
type="application/geo+json",
href=request.build_absolute_uri(f"{uri_prefix}{collection.id}/items"),
),
],
)
Expand Down Expand Up @@ -298,6 +301,9 @@ class PatchFeatureSchema(FeatureWithoutId):
FeatureCollectionSchema = FeatureCollection[FeatureSchema]

PrimaryKeyType, _ = get_schema_field(collection.model_class._meta.pk)
# get_schema_field returns type as Union[int, None] if there is a default value
if get_origin(PrimaryKeyType) is Union:
PrimaryKeyType = get_args(PrimaryKeyType)[0]

foreign_key_fields = {
field.name: field.remote_field.model
Expand Down
6 changes: 3 additions & 3 deletions django_oapif/conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def conformance(request: HttpRequest):
"http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/collections",
"http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core",
"http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson",
"http://www.opengis.net/spec/ogcapi-features-1/1.0/req/oas30",
"http://www.opengis.net/spec/ogcapi-features-1/1.0/req/oas31",
"http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30",
"http://www.opengis.net/spec/ogcapi-features-2/1.0/conf/crs",
"http://www.opengis.net/spec/ogcapi-features-4/1.0/req/create-replace-delete",
"http://www.opengis.net/spec/ogcapi-features-4/1.0/conf/create-replace-delete",
"http://www.opengis.net/spec/ogcapi-features-4/1.0/conf/update",
"http://www.opengis.net/spec/ogcapi-features-4/1.0/conf/features",
"http://www.opengis.net/spec/ogcapi-features-5/1.0/conf/core-roles-features",
"http://www.opengis.net/spec/ogcapi-features-5/1.0/conf/schemas",
]
)
Expand Down
12 changes: 5 additions & 7 deletions django_oapif/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ def model_dump(self, *, exclude_none=True, **kwargs):

class OAPIFLink(OAPIFBaseSchema):
href: str
rel: str | None = None
type: str | None = None
hreflang: str | None = None
title: str | None = None
length: int | None = None
rel: str
type: str
title: str


class OAPIFRoot(OAPIFBaseSchema):
title: str | None = None
description: str | None = None
title: str
description: str
links: list[OAPIFLink]


Expand Down
Loading