summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2022-08-12 12:18:51 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-08-12 13:26:35 +0200
commit4fcba800b84fc5fb53cdc70e4bea37ec958516fd (patch)
tree4ca13bb1947503e1a1202a0513deda760bc8090e /django
parent8c3046daade8d9b019928f96e53629b03060fe73 (diff)
Fixed #33924 -- Deprecated BaseGeometryWidget.map_height/map_width attributes.
Diffstat (limited to 'django')
-rw-r--r--django/contrib/admin/static/admin/css/widgets.css6
-rw-r--r--django/contrib/gis/forms/widgets.py17
-rw-r--r--django/contrib/gis/static/gis/js/OLMapWidget.js2
-rw-r--r--django/contrib/gis/templates/gis/openlayers.html1
4 files changed, 24 insertions, 2 deletions
diff --git a/django/contrib/admin/static/admin/css/widgets.css b/django/contrib/admin/static/admin/css/widgets.css
index cd1d6b4145..0e14efe50d 100644
--- a/django/contrib/admin/static/admin/css/widgets.css
+++ b/django/contrib/admin/static/admin/css/widgets.css
@@ -578,3 +578,9 @@ select + .related-widget-wrapper-link,
.related-widget-wrapper-link + .related-widget-wrapper-link {
margin-left: 7px;
}
+
+/* GIS MAPS */
+.dj_map {
+ width: 600px;
+ height: 400px;
+}
diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py
index 0f53ee2e96..5f169e9cb3 100644
--- a/django/contrib/gis/forms/widgets.py
+++ b/django/contrib/gis/forms/widgets.py
@@ -1,4 +1,5 @@
import logging
+import warnings
from django.conf import settings
from django.contrib.gis import gdal
@@ -6,6 +7,7 @@ from django.contrib.gis.geometry import json_regex
from django.contrib.gis.geos import GEOSException, GEOSGeometry
from django.forms.widgets import Widget
from django.utils import translation
+from django.utils.deprecation import RemovedInDjango51Warning
logger = logging.getLogger("django.contrib.gis")
@@ -18,8 +20,8 @@ class BaseGeometryWidget(Widget):
geom_type = "GEOMETRY"
map_srid = 4326
- map_width = 600
- map_height = 400
+ map_width = 600 # RemovedInDjango51Warning
+ map_height = 400 # RemovedInDjango51Warning
display_raw = False
supports_3d = False
@@ -29,6 +31,17 @@ class BaseGeometryWidget(Widget):
self.attrs = {}
for key in ("geom_type", "map_srid", "map_width", "map_height", "display_raw"):
self.attrs[key] = getattr(self, key)
+ if (
+ (attrs and ("map_width" in attrs or "map_height" in attrs))
+ or self.map_width != 600
+ or self.map_height != 400
+ ):
+ warnings.warn(
+ "The map_height and map_width widget attributes are deprecated. Please "
+ "use CSS to size map widgets.",
+ category=RemovedInDjango51Warning,
+ stacklevel=2,
+ )
if attrs:
self.attrs.update(attrs)
diff --git a/django/contrib/gis/static/gis/js/OLMapWidget.js b/django/contrib/gis/static/gis/js/OLMapWidget.js
index 839c8cd7cc..fe944a4a87 100644
--- a/django/contrib/gis/static/gis/js/OLMapWidget.js
+++ b/django/contrib/gis/static/gis/js/OLMapWidget.js
@@ -61,6 +61,8 @@ class MapWidget {
this.options.base_layer = new ol.layer.Tile({source: new ol.source.OSM()});
}
+ // RemovedInDjango51Warning: when the deprecation ends, remove setting
+ // width/height (3 lines below).
const mapContainer = document.getElementById(this.options.map_id);
mapContainer.style.width = `${mapContainer.dataset.width}px`;
mapContainer.style.height = `${mapContainer.dataset.height}px`;
diff --git a/django/contrib/gis/templates/gis/openlayers.html b/django/contrib/gis/templates/gis/openlayers.html
index bde2650ca2..2849813c6e 100644
--- a/django/contrib/gis/templates/gis/openlayers.html
+++ b/django/contrib/gis/templates/gis/openlayers.html
@@ -1,6 +1,7 @@
{% load i18n l10n %}
<div id="{{ id }}_div_map" class="dj_map_wrapper">
+ {# RemovedInDjango51Warning: when the deprecation ends, remove data-width and data-height attributes. #}
<div id="{{ id }}_map" class="dj_map" data-width="{{ map_width }}" data-height="{{ map_height }}"></div>
{% if not disabled %}<span class="clear_features"><a href="">{% translate "Delete all Features" %}</a></span>{% endif %}
{% if display_raw %}<p>{% translate "Debugging window (serialized value)" %}</p>{% endif %}