Backend style fixes
This commit is contained in:
parent
13c8436d98
commit
a7d7581c1b
8 changed files with 38 additions and 9 deletions
|
@ -5,4 +5,5 @@ class ApiConfig(AppConfig):
|
||||||
name = 'right_tree.api'
|
name = 'right_tree.api'
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
|
# flake8: noqa
|
||||||
import right_tree.api.signals
|
import right_tree.api.signals
|
||||||
|
|
|
@ -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
|
from .wms_utils import get_point_from_coordinates
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,11 +17,13 @@ def is_in_auckland(coordinates):
|
||||||
print(eco_district.ecologic_2)
|
print(eco_district.ecologic_2)
|
||||||
return eco_district is not None and eco_district.ecologic_2.name == 'Auckland'
|
return eco_district is not None and eco_district.ecologic_2.name == 'Auckland'
|
||||||
|
|
||||||
|
|
||||||
def is_in_christchurch(coordinates):
|
def is_in_christchurch(coordinates):
|
||||||
pnt = get_point_from_coordinates(coordinates)
|
pnt = get_point_from_coordinates(coordinates)
|
||||||
in_chch = ChristchurchRegion.objects.filter(geom__intersects=pnt).first()
|
in_chch = ChristchurchRegion.objects.filter(geom__intersects=pnt).first()
|
||||||
return in_chch is not None
|
return in_chch is not None
|
||||||
|
|
||||||
|
|
||||||
def get_filtered_plants(request):
|
def get_filtered_plants(request):
|
||||||
try:
|
try:
|
||||||
ak = ActivationKey.objects.get(key=request.query_params['key'])
|
ak = ActivationKey.objects.get(key=request.query_params['key'])
|
||||||
|
|
|
@ -11,7 +11,6 @@ from django.contrib.postgres.indexes import OpClass
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SoilOrder(models.Model):
|
class SoilOrder(models.Model):
|
||||||
code = models.CharField(unique=True, max_length=1)
|
code = models.CharField(unique=True, max_length=1)
|
||||||
name = models.CharField(unique=True, max_length=50)
|
name = models.CharField(unique=True, max_length=50)
|
||||||
|
|
|
@ -32,7 +32,7 @@ def get_location_filters(questionnaire):
|
||||||
address = get_address_from_coordinates(questionnaire.location)
|
address = get_address_from_coordinates(questionnaire.location)
|
||||||
|
|
||||||
filter_rows.append(['Point 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(['Ecological district:', eco_district_layer.ecologic_2 or ' '])
|
||||||
filter_rows.append(['Property address:', address['full_address'] if address is not None else ' '])
|
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 []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def get_filter_values(params):
|
def get_filter_values(params):
|
||||||
""" Retrives all selected values/filters from the request parameters
|
""" Retrives all selected values/filters from the request parameters
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,5 +1,18 @@
|
||||||
from rest_framework import serializers, exceptions
|
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):
|
class ToleranceLevelSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
@ -39,8 +52,10 @@ class SoilVariantSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
model = SoilVariant
|
model = SoilVariant
|
||||||
fields = ['name']
|
fields = ['name']
|
||||||
|
|
||||||
|
|
||||||
class HabitatImageSerializer(serializers.HyperlinkedModelSerializer):
|
class HabitatImageSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
id = serializers.ReadOnlyField()
|
id = serializers.ReadOnlyField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = HabitatImage
|
model = HabitatImage
|
||||||
fields = ['id', 'name', 'image_filename']
|
fields = ['id', 'name', 'image_filename']
|
||||||
|
@ -54,6 +69,7 @@ class HabitatSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
model = Habitat
|
model = Habitat
|
||||||
fields = ['id', 'name', 'images']
|
fields = ['id', 'name', 'images']
|
||||||
|
|
||||||
|
|
||||||
class ZoneSerializer(serializers.HyperlinkedModelSerializer):
|
class ZoneSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
id = serializers.ReadOnlyField()
|
id = serializers.ReadOnlyField()
|
||||||
habitat = HabitatSerializer()
|
habitat = HabitatSerializer()
|
||||||
|
@ -63,6 +79,8 @@ class ZoneSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
model = Zone
|
model = Zone
|
||||||
fields = ['id', 'name', 'variant',
|
fields = ['id', 'name', 'variant',
|
||||||
'refined_variant', 'habitat', 'related_svg_segment', 'redirect_habitat', 'ignore_soil_order_filter', 'ignore_location_filter', 'tooltip_display_text']
|
'refined_variant', 'habitat', 'related_svg_segment', 'redirect_habitat', 'ignore_soil_order_filter', 'ignore_location_filter', 'tooltip_display_text']
|
||||||
|
|
||||||
|
|
||||||
class LocationDetailsSerializer(serializers.Serializer):
|
class LocationDetailsSerializer(serializers.Serializer):
|
||||||
ecologic_1 = serializers.CharField(max_length=50)
|
ecologic_1 = serializers.CharField(max_length=50)
|
||||||
ecologic_2 = serializers.CharField(max_length=50)
|
ecologic_2 = serializers.CharField(max_length=50)
|
||||||
|
|
|
@ -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 .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 .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 .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 .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
|
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))
|
return SoilOrder.objects.filter(soillayer__geom__intersects=Point(lng, lat, srid=4326))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EcologicalDistrictViewSet(viewsets.ModelViewSet):
|
class EcologicalDistrictViewSet(viewsets.ModelViewSet):
|
||||||
""" Filtered viewset for ecological district/region details.
|
""" 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"""
|
"""Generate a prospective key and redirect to the Stripe payment portal"""
|
||||||
|
|
||||||
stripe.api_key = settings.STRIPE_API_KEY
|
stripe.api_key = settings.STRIPE_API_KEY
|
||||||
price_id = settings.STRIPE_DIGITAL_PRICE_ID
|
price_id = settings.STRIPE_DIGITAL_PRICE_ID
|
||||||
extra_kwargs = {}
|
extra_kwargs = {}
|
||||||
|
|
||||||
key = ActivationKey.key_default()
|
key = ActivationKey.key_default()
|
||||||
|
|
|
@ -53,7 +53,7 @@ def wfs_getfeature(endpoint, **kwargs):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return response.json()
|
return response.json()
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError:
|
||||||
raise WFSError(
|
raise WFSError(
|
||||||
f"Failed to make WFS request to {url}: {response.content}")
|
f"Failed to make WFS request to {url}: {response.content}")
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ SECRET_KEY = os.getenv("DJANGO_SECRET_KEY", 'django-insecure-5t05qc2&14xuot4lgs#
|
||||||
DEBUG = os.getenv('DJANGO_DEBUG_MODE', '') != 'False'
|
DEBUG = os.getenv('DJANGO_DEBUG_MODE', '') != 'False'
|
||||||
|
|
||||||
# os.getenv("ALLOWED_HOSTS", "").split(","),
|
# os.getenv("ALLOWED_HOSTS", "").split(","),
|
||||||
ALLOWED_HOSTS = [BASE_URL, "localhost"]
|
ALLOWED_HOSTS = [BASE_URL, "localhost"]
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
Loading…
Reference in a new issue