Skip to content

Commit

Permalink
✨ [#2173] Define map background url on request
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
robinmolen committed Dec 3, 2024
1 parent a0964d4 commit bf3f13c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/openforms/formio/components/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bf3f13c

Please sign in to comment.