Skip to content

Commit

Permalink
Re-implemented 'finalize_response' with kind help from https://stacko…
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Aug 2, 2023
1 parent 0305ae8 commit 989488c
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/django_oapif/decorators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Callable, Dict, Optional

from django.db.models import Model
from rest_framework import response, viewsets
from rest_framework import viewsets
from rest_framework_gis.serializers import GeoFeatureModelSerializer

from django_oapif.metadata import OAPIFMetadata
Expand Down Expand Up @@ -80,11 +80,15 @@ class Viewset(OAPIFDescribeModelViewSetMixin, viewsets.ModelViewSet):
# Metadata
metadata_class = OAPIFMetadata

def options(self, request, *args, **kwargs) -> response.Response:
allowed_actions = self.metadata_class().determine_actions(request, self)
allowed_actions = ", ".join(allowed_actions.keys())
data = self.metadata_class().determine_metadata(request, self)
return response.Response(data, headers={"Allow": allowed_actions})
def finalize_response(self, request, response, *args, **kwargs):
response = super().finalize_response(request, response, *args, **kwargs)
if request.method == "OPTIONS":
allowed_actions = self.metadata_class().determine_actions(
request, self
)
allowed_actions = ", ".join(allowed_actions.keys())
response.headers["Allow"] = allowed_actions
return response

# ON HOLD, WAITING ON GeoFeatureModelSerializer to admit of null geometries
"""
Expand Down

0 comments on commit 989488c

Please sign in to comment.