Refs #25706 -- Removed inline CSS in the openlayers widget template.

This commit is contained in:
Claude Paroz 2022-07-30 23:52:17 +02:00 committed by Mariusz Felisiak
parent 2aa6fb2121
commit 44c24bf028
6 changed files with 23 additions and 14 deletions

View File

@ -1,3 +1,11 @@
.dj_map_wrapper {
position: relative;
float: left;
}
html[dir="rtl"] .dj_map_wrapper {
float: right;
}
.switch-type { .switch-type {
background-repeat: no-repeat; background-repeat: no-repeat;
cursor: pointer; cursor: pointer;

View File

@ -61,6 +61,9 @@ class MapWidget {
this.options.base_layer = new ol.layer.Tile({source: new ol.source.OSM()}); this.options.base_layer = new ol.layer.Tile({source: new ol.source.OSM()});
} }
const mapContainer = document.getElementById(this.options.map_id);
mapContainer.style.width = `${mapContainer.dataset.width}px`;
mapContainer.style.height = `${mapContainer.dataset.height}px`;
this.map = this.createMap(); this.map = this.createMap();
this.featureCollection = new ol.Collection(); this.featureCollection = new ol.Collection();
this.featureOverlay = new ol.layer.Vector({ this.featureOverlay = new ol.layer.Vector({

View File

@ -1,17 +1,11 @@
{% load i18n l10n %} {% load i18n l10n %}
<style type="text/css">{% block map_css %}{% get_current_language_bidi as LANGUAGE_BIDI %}
#{{ id }}_map { width: {{ map_width }}px; height: {{ map_height }}px; }
#{{ id }}_map .aligned label { float: inherit; }
#{{ id }}_div_map { position: relative; vertical-align: top; float: {{ LANGUAGE_BIDI|yesno:"right,left" }}; }
{% if not display_raw %}#{{ id }} { display: none; }{% endif %}
{% endblock %}
</style>
<div id="{{ id }}_div_map"> <div id="{{ id }}_div_map" class="dj_map_wrapper">
<div id="{{ id }}_map"></div> <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 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 %} {% if display_raw %}<p>{% translate "Debugging window (serialized value)" %}</p>{% endif %}
<textarea id="{{ id }}" class="vSerializedField required" cols="150" rows="10" name="{{ name }}">{{ serialized }}</textarea> <textarea id="{{ id }}" class="vSerializedField required" cols="150" rows="10" name="{{ name }}"
{% if not display_raw %} hidden{% endif %}>{{ serialized }}</textarea>
<script> <script>
{% block base_layer %} {% block base_layer %}
var base_layer = new ol.layer.Tile({ var base_layer = new ol.layer.Tile({

View File

@ -63,6 +63,10 @@ Minor features
* The :class:`~django.contrib.gis.geoip2.GeoIP2` class now supports ``.mmdb`` * The :class:`~django.contrib.gis.geoip2.GeoIP2` class now supports ``.mmdb``
files downloaded from DB-IP. files downloaded from DB-IP.
* The OpenLayers template widget no longer includes inline CSS (which also
removes the former ``map_css`` block) to better comply with a strict Content
Security Policy.
:mod:`django.contrib.messages` :mod:`django.contrib.messages`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -16,7 +16,7 @@ class GeoAdminTest(SimpleTestCase):
output = str(form["point"]) output = str(form["point"])
self.assertInHTML( self.assertInHTML(
'<textarea id="id_point" class="vSerializedField required" cols="150"' '<textarea id="id_point" class="vSerializedField required" cols="150"'
' rows="10" name="point"></textarea>', ' rows="10" name="point" hidden></textarea>',
output, output,
) )
@ -27,7 +27,7 @@ class GeoAdminTest(SimpleTestCase):
output = str(form["point"]) output = str(form["point"])
self.assertInHTML( self.assertInHTML(
'<textarea id="id_point" class="vSerializedField required" cols="150"' '<textarea id="id_point" class="vSerializedField required" cols="150"'
' rows="10" name="point"></textarea>', ' rows="10" name="point" hidden></textarea>',
output, output,
) )
self.assertEqual(len(cm.records), 1) self.assertEqual(len(cm.records), 1)

View File

@ -166,12 +166,12 @@ class GeometryFieldTest(SimpleTestCase):
self.assertInHTML( self.assertInHTML(
'<textarea id="id_pt2" class="vSerializedField required" cols="150"' '<textarea id="id_pt2" class="vSerializedField required" cols="150"'
' rows="10" name="pt2"></textarea>', ' rows="10" name="pt2" hidden></textarea>',
output, output,
) )
self.assertInHTML( self.assertInHTML(
'<textarea id="id_pt3" class="vSerializedField required" cols="150"' '<textarea id="id_pt3" class="vSerializedField required" cols="150"'
' rows="10" name="pt3"></textarea>', ' rows="10" name="pt3" hidden></textarea>',
output, output,
) )
# Only the invalid PNT(0) triggers an error log entry. # Only the invalid PNT(0) triggers an error log entry.