diff --git a/backend/right_tree/api/apps.py b/backend/right_tree/api/apps.py index 10ab459..7101028 100644 --- a/backend/right_tree/api/apps.py +++ b/backend/right_tree/api/apps.py @@ -5,4 +5,5 @@ class ApiConfig(AppConfig): name = 'right_tree.api' def ready(self): + # flake8: noqa import right_tree.api.signals diff --git a/backend/right_tree/api/filters.py b/backend/right_tree/api/filters.py index 96b52c0..730ab57 100644 --- a/backend/right_tree/api/filters.py +++ b/backend/right_tree/api/filters.py @@ -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']) diff --git a/backend/right_tree/api/models.py b/backend/right_tree/api/models.py index 55a4257..69b542e 100644 --- a/backend/right_tree/api/models.py +++ b/backend/right_tree/api/models.py @@ -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) diff --git a/backend/right_tree/api/resource_generation_utils.py b/backend/right_tree/api/resource_generation_utils.py index 5f3b9e1..d667eb6 100644 --- a/backend/right_tree/api/resource_generation_utils.py +++ b/backend/right_tree/api/resource_generation_utils.py @@ -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 """ diff --git a/backend/right_tree/api/serializers.py b/backend/right_tree/api/serializers.py index f8e8802..592b8e0 100644 --- a/backend/right_tree/api/serializers.py +++ b/backend/right_tree/api/serializers.py @@ -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) diff --git a/backend/right_tree/api/views.py b/backend/right_tree/api/views.py index 8047d12..d179a4c 100644 --- a/backend/right_tree/api/views.py +++ b/backend/right_tree/api/views.py @@ -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. """ @@ -273,7 +272,7 @@ def purchase_key(request): """Generate a prospective key and redirect to the Stripe payment portal""" stripe.api_key = settings.STRIPE_API_KEY - price_id = settings.STRIPE_DIGITAL_PRICE_ID + price_id = settings.STRIPE_DIGITAL_PRICE_ID extra_kwargs = {} key = ActivationKey.key_default() diff --git a/backend/right_tree/api/wms_utils.py b/backend/right_tree/api/wms_utils.py index bcadac0..e978266 100644 --- a/backend/right_tree/api/wms_utils.py +++ b/backend/right_tree/api/wms_utils.py @@ -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}") diff --git a/backend/right_tree/settings.py b/backend/right_tree/settings.py index 7631c31..af5cfe3 100644 --- a/backend/right_tree/settings.py +++ b/backend/right_tree/settings.py @@ -28,7 +28,7 @@ SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", 'django-insecure-5t05qc2&14xuot4lgs# DEBUG = os.getenv('DJANGO_DEBUG_MODE', '') != 'False' # os.getenv("ALLOWED_HOSTS", "").split(","), -ALLOWED_HOSTS = [BASE_URL, "localhost"] +ALLOWED_HOSTS = [BASE_URL, "localhost"] # Application definition