Skip to content

Commit

Permalink
removed unrelated docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Aug 10, 2023
1 parent 51d76c6 commit 1545498
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
django>=4
django-computedfields
fiona
psycopg2-binary
transifex-client
djangorestframework
Expand Down
5 changes: 4 additions & 1 deletion src/django_oapif/decorators.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from typing import Any, Callable, Dict, Optional

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

from django_oapif.metadata import OAPIFMetadata
from django_oapif.mixins import OAPIFDescribeModelViewSetMixin
from django_oapif.renderers import FGBRenderer
from django_oapif.urls import oapif_router

from .filters import BboxFilterBackend
Expand Down Expand Up @@ -57,6 +58,7 @@ class Meta:
else:
"""
viewset_serializer_class = AutoSerializer
viewset_renderer_classes = [renderers.JSONRenderer, FGBRenderer]
viewset_oapif_geom_lookup = (
"geom" # one day this will be retrieved automatically from the serializer
)
Expand All @@ -65,6 +67,7 @@ class Meta:
class Viewset(OAPIFDescribeModelViewSetMixin, viewsets.ModelViewSet):
queryset = Model.objects.all()
serializer_class = viewset_serializer_class
renderer_classes = viewset_renderer_classes

# TODO: these should probably be moved to the mixin
oapif_title = Model._meta.verbose_name
Expand Down
28 changes: 28 additions & 0 deletions src/django_oapif/renderers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import io
from typing import OrderedDict

import fiona
from django.http import StreamingHttpResponse
from rest_framework import renderers


class FGBRenderer(renderers.BaseRenderer):
format = "fgb"
media_type = "application/octet-stream"
# FIXME: This should be sent by the model.
schema = {"geometry": "Point", "properties": {"name": "str", "_serialized": "str"}}

def render(
self, data: OrderedDict, accepted_media_type=None, renderer_context=None
) -> StreamingHttpResponse:
"""Renders pre-serialized Python objects as a flatgeobuf binary stream"""
features = (fiona.Feature.from_dict(obj) for obj in data["features"])
buffer_wrapper = io.BytesIO()

with fiona.open(
buffer_wrapper, mode="w", driver="FlatGeobuf", schema=self.schema
) as fh:
for feature in features:
fh.write(feature)

return StreamingHttpResponse(buffer_wrapper.getvalue())

0 comments on commit 1545498

Please sign in to comment.