Backend style fixes

This commit is contained in:
Matthew Northcott 2023-04-20 15:12:22 +12:00
parent 13c8436d98
commit a7d7581c1b
8 changed files with 38 additions and 9 deletions

View file

@ -5,4 +5,5 @@ class ApiConfig(AppConfig):
name = 'right_tree.api'
def ready(self):
# flake8: noqa
import right_tree.api.signals

View file

@ -1,4 +1,13 @@
from .models import Plant, EcologicalRegion, EcologicalDistrictLayer, ChristchurchRegion, SoilOrder, SoilVariant, ActivationKey, Questionnaire
from .models import (
Plant,
EcologicalRegion,
EcologicalDistrictLayer,
ChristchurchRegion,
SoilOrder,
SoilVariant,
ActivationKey,
Questionnaire
)
from .wms_utils import get_point_from_coordinates
@ -8,11 +17,13 @@ def is_in_auckland(coordinates):
print(eco_district.ecologic_2)
return eco_district is not None and eco_district.ecologic_2.name == 'Auckland'
def is_in_christchurch(coordinates):
pnt = get_point_from_coordinates(coordinates)
in_chch = ChristchurchRegion.objects.filter(geom__intersects=pnt).first()
return in_chch is not None
def get_filtered_plants(request):
try:
ak = ActivationKey.objects.get(key=request.query_params['key'])

View file

@ -11,7 +11,6 @@ from django.contrib.postgres.indexes import OpClass
from django.utils.text import slugify
class SoilOrder(models.Model):
code = models.CharField(unique=True, max_length=1)
name = models.CharField(unique=True, max_length=50)

View file

@ -32,7 +32,7 @@ def get_location_filters(questionnaire):
address = get_address_from_coordinates(questionnaire.location)
filter_rows.append(['Point coordinates:', questionnaire.location])
filter_rows.append(['Ecological region:', eco_district_layer.ecologic_1 or '' ])
filter_rows.append(['Ecological region:', eco_district_layer.ecologic_1 or ''])
filter_rows.append(['Ecological district:', eco_district_layer.ecologic_2 or ' '])
filter_rows.append(['Property address:', address['full_address'] if address is not None else ' '])
@ -78,6 +78,7 @@ def get_additional_region_info(questionnaire):
return []
def get_filter_values(params):
""" Retrives all selected values/filters from the request parameters
"""

View file

@ -1,5 +1,18 @@
from rest_framework import serializers, exceptions
from right_tree.api.models import *
from .models import (
ToleranceLevel,
EcologicalRegion,
EcologicalDistrictLayer,
SoilOrder,
SoilVariant,
HabitatImage,
Habitat,
Zone,
Plant,
Questionnaire,
ActivationKey,
)
class ToleranceLevelSerializer(serializers.HyperlinkedModelSerializer):
@ -39,8 +52,10 @@ class SoilVariantSerializer(serializers.HyperlinkedModelSerializer):
model = SoilVariant
fields = ['name']
class HabitatImageSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
class Meta:
model = HabitatImage
fields = ['id', 'name', 'image_filename']
@ -54,6 +69,7 @@ class HabitatSerializer(serializers.HyperlinkedModelSerializer):
model = Habitat
fields = ['id', 'name', 'images']
class ZoneSerializer(serializers.HyperlinkedModelSerializer):
id = serializers.ReadOnlyField()
habitat = HabitatSerializer()
@ -63,6 +79,8 @@ class ZoneSerializer(serializers.HyperlinkedModelSerializer):
model = Zone
fields = ['id', 'name', 'variant',
'refined_variant', 'habitat', 'related_svg_segment', 'redirect_habitat', 'ignore_soil_order_filter', 'ignore_location_filter', 'tooltip_display_text']
class LocationDetailsSerializer(serializers.Serializer):
ecologic_1 = serializers.CharField(max_length=50)
ecologic_2 = serializers.CharField(max_length=50)

View file

@ -15,7 +15,7 @@ from rest_framework.response import Response
from .models import Habitat, HabitatImage, Plant, EcologicalDistrictLayer, SoilOrder, Zone, Questionnaire, ActivationKey, ActivationKeySet, Customer, CustomerAddress
from .serializers import HabitatImageSerializer, HabitatSerializer, PlantSerializer, SoilOrderSerializer, EcologicalDistrictLayerSerializer, AddressSerializer, ZoneSerializer, QuestionnaireSerializer
from .filters import *
from .filters import get_filtered_plants, is_in_auckland, is_in_christchurch
from .wms_utils import get_address_from_coordinates, search_address
from .resource_generation_utils import generate_csv, get_filter_values, serialize_plants_queryset, create_planting_guide_pdf, PLANTING_GUIDE_PDF_FILENAME, storage
from .redis import redis_client
@ -51,7 +51,6 @@ class SoilOrderViewSet(viewsets.ModelViewSet):
return SoilOrder.objects.filter(soillayer__geom__intersects=Point(lng, lat, srid=4326))
class EcologicalDistrictViewSet(viewsets.ModelViewSet):
""" Filtered viewset for ecological district/region details.
"""

View file

@ -53,7 +53,7 @@ def wfs_getfeature(endpoint, **kwargs):
try:
return response.json()
except json.JSONDecodeError as e:
except json.JSONDecodeError:
raise WFSError(
f"Failed to make WFS request to {url}: {response.content}")