From 880bca35016acce2bd1a30b01477278634626d10 Mon Sep 17 00:00:00 2001 From: relikd Date: Thu, 27 Jun 2024 01:50:08 +0200 Subject: [PATCH] fix: options as json --- map_location/fields.py | 13 ++++++++----- map_location/templates/forms/map-location.html | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/map_location/fields.py b/map_location/fields.py index df6097a..d6248cc 100644 --- a/map_location/fields.py +++ b/map_location/fields.py @@ -1,7 +1,9 @@ -from typing import NamedTuple from django.db import models from django.forms import Widget +import json +from typing import NamedTuple + class Position(NamedTuple): lat: float @@ -24,10 +26,11 @@ class MapLocationWidget(Widget): 'leaflet/locate/L.Control.Locate.min.js', 'map-location.js'] - # def get_context(self, name, value, attrs): - # context = super().get_context(name, value, attrs) - # context['id'] = attrs.get('id') - # return context + def get_context(self, name, value, attrs): + context = super().get_context(name, value, attrs) + context['map_options'] = json.dumps( + context['widget']['attrs'].get('options')) + return context class LocationField(models.Field): diff --git a/map_location/templates/forms/map-location.html b/map_location/templates/forms/map-location.html index a64fdde..715b6a3 100644 --- a/map_location/templates/forms/map-location.html +++ b/map_location/templates/forms/map-location.html @@ -3,6 +3,6 @@
Remove \ No newline at end of file