Skip to content

Commit

Permalink
Move RegionFeatureCollectionSerializer to serializers file
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt committed Sep 28, 2023
1 parent ecd671c commit 7764baa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 10 additions & 0 deletions uvdat/core/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from django.contrib.gis.serializers import geojson
from rest_framework import serializers

from uvdat.core.models import Chart, City, Dataset, DerivedRegion, NetworkNode, SimulationResult
Expand Down Expand Up @@ -51,6 +52,15 @@ class Meta:
model = SimulationResult


class RegionFeatureCollectionSerializer(geojson.Serializer):
# Override this method to ensure the pk field is a number instead of a string
def get_dump_object(self, obj):
val = super().get_dump_object(obj)
val["properties"]["id"] = int(val["properties"].pop("pk"))

return val


class DerivedRegionListSerializer(serializers.ModelSerializer):
class Meta:
model = DerivedRegion
Expand Down
12 changes: 1 addition & 11 deletions uvdat/core/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import json
from pathlib import Path
import tempfile
from typing import Any

from django.contrib.gis.db.models.aggregates import Union
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.serializers import geojson
from django.db import transaction
from django.http import HttpResponse
from django_large_image.rest import LargeImageFileDetailMixin
Expand All @@ -26,6 +24,7 @@
DerivedRegionDetailSerializer,
DerivedRegionListSerializer,
NetworkNodeSerializer,
RegionFeatureCollectionSerializer,
SimulationResultSerializer,
)
from uvdat.core.tasks.charts import add_gcc_chart_datum
Expand All @@ -34,15 +33,6 @@
from uvdat.core.tasks.simulations import get_available_simulations, run_simulation


class RegionFeatureCollectionSerializer(geojson.Serializer):
# Override this method to ensure the pk field is a number instead of a string
def get_dump_object(self, obj: Any) -> Any:
val = super().get_dump_object(obj)
val["properties"]["id"] = int(val["properties"].pop("pk"))

return val


class DerivedRegionViewSet(mixins.RetrieveModelMixin, mixins.ListModelMixin, GenericViewSet):
queryset = DerivedRegion.objects.all()
serializer_class = DerivedRegionListSerializer
Expand Down

0 comments on commit 7764baa

Please sign in to comment.