From 022d9d15a73fbed6f7f28099ee74bedf8cdec6aa Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 13 Jan 2022 09:27:35 +0100 Subject: [PATCH] #67 Parcel error fix * adds workaround in case of received WFS exception -> routine waits 1 second and tries to rerun for another time. If this does fail as well, the routine will end without a result * adds mailto shortcut to contact button in footer for a quick fix --- konova/contexts.py | 5 +++-- konova/utils/wfs/spatial.py | 19 +++++++++++++++++++ templates/footer.html | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/konova/contexts.py b/konova/contexts.py index 470161c..751e355 100644 --- a/konova/contexts.py +++ b/konova/contexts.py @@ -8,7 +8,7 @@ Created on: 16.11.20 from django.http import HttpRequest from konova.sub_settings.context_settings import BASE_TITLE, HELP_LINK, BASE_FRONTEND_TITLE -from konova.sub_settings.django_settings import LANGUAGE_CODE +from konova.sub_settings.django_settings import EMAIL_REPLY_TO class BaseContext: @@ -24,7 +24,8 @@ class BaseContext: "language": request.LANGUAGE_CODE, "user": request.user, "current_role": None, - "help_link": HELP_LINK + "help_link": HELP_LINK, + "CONTACT_MAIL": EMAIL_REPLY_TO, } # Add additional context, derived from given parameters diff --git a/konova/utils/wfs/spatial.py b/konova/utils/wfs/spatial.py index 11d8e39..34b037c 100644 --- a/konova/utils/wfs/spatial.py +++ b/konova/utils/wfs/spatial.py @@ -6,6 +6,7 @@ Created on: 17.12.21 """ from abc import abstractmethod +from time import sleep import requests import xmltodict @@ -122,6 +123,7 @@ class ParcelWFSFetcher(AbstractWFSFetcher): spatial_operator: str = "Intersects", filter_srid: str = None, start_index: int = 0, + rerun_on_exception: bool = True ): """ Fetches features from the WFS using POST @@ -159,6 +161,23 @@ class ParcelWFSFetcher(AbstractWFSFetcher): {}, ) + # Check if collection is an exception and does not contain the requested data + if len(collection) == 0: + exception = content.get( + "ows:ExceptionReport", + {} + ) + if len(exception) > 0 and rerun_on_exception: + # Wait a second before another try + sleep(1) + self.get_features( + typenames, + spatial_operator, + filter_srid, + start_index, + rerun_on_exception=False + ) + members = collection.get( "wfs:member", [], diff --git a/templates/footer.html b/templates/footer.html index 227f5ac..af8fd94 100644 --- a/templates/footer.html +++ b/templates/footer.html @@ -9,7 +9,7 @@ {% trans 'Impressum' %} - {% trans 'Contact' %} + {% trans 'Contact' %}