Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Returning hex wkb #3

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions signalo/signalo_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Pole(ComputedFieldsModel):
def _serialized(self):
return f'{{"id": "{str(self.id)}", "type": "Feature", "geometry": {self.geom.geojson}, "properties": {{"name": "{self.name}"}}}}'

@property
def geom_wkb(self):
return self.geom.hexewkb


class Sign(ComputedFieldsModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Expand Down
31 changes: 10 additions & 21 deletions signalo/signalo_app/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.conf import settings
from django.contrib.gis.geos import Polygon
from django.http import HttpResponse
from rest_framework.response import Response

from django_oapif.mixins import OAPIFDescribeModelViewSetMixin
from rest_framework import viewsets
from rest_framework import viewsets, serializers
from rest_framework_gis.serializers import GeoFeatureModelSerializer
from rest_framework.pagination import LimitOffsetPagination
from signalo_app.models import Pole, Sign


Expand All @@ -17,12 +20,13 @@ def __init__(self, data):
super(OapifResponse, self).__init__(data)


class PoleSerializer(GeoFeatureModelSerializer):
class PoleSerializer(serializers.ModelSerializer):
# used only for API route
geom_wkb = serializers.ReadOnlyField()

class Meta:
model = Sign
fields = "__all__"
geo_field = "geom"
model = Pole
fields = ["id", "geom_wkb", "name", ]


class SignSerializer(GeoFeatureModelSerializer):
Expand All @@ -47,6 +51,7 @@ class SignViewset(OAPIFDescribeModelViewSetMixin, viewsets.ModelViewSet):

class PoleViewset(OAPIFDescribeModelViewSetMixin, viewsets.ModelViewSet):
serializer_class = PoleSerializer # used only for API route
pagination_class = LimitOffsetPagination
oapif_title = "PoleOAPIFModel"
oapif_description = "PoleOAPIFModel layer"
oapif_geom_lookup = (
Expand All @@ -56,22 +61,6 @@ class PoleViewset(OAPIFDescribeModelViewSetMixin, viewsets.ModelViewSet):
settings.SRID
) # (one day this will be retrieved automatically from the DB field)

def list(self, request, *args, **kwargs):
queryset = self.filter_queryset(self.get_queryset())

queryset = queryset.values_list("_serialized", flat=True)

serialized_poles = []

page = self.paginate_queryset(queryset)
if page is not None:
for pole in page:
serialized_poles.append(pole or "")
return self.get_paginated_response(serialized_poles)

for pole in queryset:
serialized_poles.append(pole or "")
return OapifResponse(serialized_poles)

def get_queryset(self):
if self.request.GET.get("bbox"):
Expand Down