From d65d66d9b0351056ee2f4be4e9b3ab31f77bd059 Mon Sep 17 00:00:00 2001 From: robinvandermolen Date: Mon, 25 Nov 2024 14:19:04 +0100 Subject: [PATCH] :sparkles: [#2173] Define map background url on request The map configuration can be edited at any moment. To make sure that we always return the correct map background url, we determined it per request. --- src/openforms/formio/components/custom.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/openforms/formio/components/custom.py b/src/openforms/formio/components/custom.py index e7521c482b..407343c6e8 100644 --- a/src/openforms/formio/components/custom.py +++ b/src/openforms/formio/components/custom.py @@ -14,7 +14,7 @@ from rest_framework.request import Request from openforms.authentication.service import AuthAttribute -from openforms.config.models import GlobalConfiguration +from openforms.config.models import GlobalConfiguration, LeafletMapBackground from openforms.submissions.models import Submission from openforms.typing import DataMapping from openforms.utils.date import TIMEZONE_AMS, datetime_in_amsterdam, format_date_value @@ -198,6 +198,16 @@ def rewrite_for_request(component, request: Request): component["initialCenter"]["lat"] = config.form_map_default_latitude component["initialCenter"]["lng"] = config.form_map_default_longitude + if component.get("backgroundIdentifier", False): + try: + leaflet_map_background = LeafletMapBackground.objects.get( + identifier=component["backgroundIdentifier"] + ) + # Write the background url information + component["url"] = leaflet_map_background.url + except LeafletMapBackground.DoesNotExist: + return None + def build_serializer_field(self, component: Component) -> serializers.ListField: validate = component.get("validate", {}) required = validate.get("required", False)