mirror of https://github.com/django/django.git
Fixed #19139 -- Made OpenLayersWidget follow GeoModelAdmin's modifiable attribute
Thanks Tim Graham for the review.
This commit is contained in:
parent
66580fe97c
commit
ce078ef976
|
@ -22,6 +22,9 @@ class OpenLayersWidget(Textarea):
|
|||
# Update the template parameters with any attributes passed in.
|
||||
if attrs:
|
||||
self.params.update(attrs)
|
||||
self.params['editable'] = self.params['modifiable']
|
||||
else:
|
||||
self.params['editable'] = True
|
||||
|
||||
# Defaulting the WKT value to a blank string -- this
|
||||
# will be tested in the JavaScript and the appropriate
|
||||
|
|
|
@ -31,7 +31,9 @@
|
|||
//]]>
|
||||
</script>
|
||||
<div id="{{ id }}_map"{% if LANGUAGE_BIDI %} dir="ltr"{% endif %}></div>
|
||||
{% if editable %}
|
||||
<a href="javascript:{{ module }}.clearFeatures()">Delete all Features</a>
|
||||
{% endif %}
|
||||
{% if display_wkt %}<p> WKT debugging window:</p>{% endif %}
|
||||
<textarea id="{{ id }}" class="vWKTField required" cols="150" rows="10" name="{{ name }}">{{ wkt }}</textarea>
|
||||
<script type="text/javascript">{% block init_function %}{{ module }}.init();{% endblock %}</script>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
from django.contrib.gis import admin
|
||||
|
||||
|
||||
class UnmodifiableAdmin(admin.OSMGeoAdmin):
|
||||
modifiable = False
|
|
@ -7,6 +7,7 @@ if HAS_GEOS:
|
|||
from django.contrib.gis import admin
|
||||
from django.contrib.gis.geos import Point
|
||||
|
||||
from .admin import UnmodifiableAdmin
|
||||
from .models import City
|
||||
|
||||
|
||||
|
@ -20,13 +21,31 @@ class GeoAdminTest(TestCase):
|
|||
self.assertTrue(any(geoadmin.openlayers_url in js for js in admin_js))
|
||||
|
||||
def test_olmap_OSM_rendering(self):
|
||||
geoadmin = admin.site._registry[City]
|
||||
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
|
||||
).render('point', Point(-79.460734, 40.18476))
|
||||
delete_all_btn = """<a href="javascript:geodjango_point.clearFeatures()">Delete all Features</a>"""
|
||||
|
||||
original_geoadmin = admin.site._registry[City]
|
||||
params = original_geoadmin.get_map_widget(City._meta.get_field('point')).params
|
||||
result = original_geoadmin.get_map_widget(City._meta.get_field('point'))(
|
||||
).render('point', Point(-79.460734, 40.18476), params)
|
||||
self.assertIn(
|
||||
"""geodjango_point.layers.base = new OpenLayers.Layer.OSM("OpenStreetMap (Mapnik)");""",
|
||||
result)
|
||||
|
||||
self.assertIn(delete_all_btn, result)
|
||||
|
||||
admin.site.unregister(City)
|
||||
admin.site.register(City, UnmodifiableAdmin)
|
||||
try:
|
||||
geoadmin = admin.site._registry[City]
|
||||
params = geoadmin.get_map_widget(City._meta.get_field('point')).params
|
||||
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
|
||||
).render('point', Point(-79.460734, 40.18476), params)
|
||||
|
||||
self.assertNotIn(delete_all_btn, result)
|
||||
finally:
|
||||
admin.site.unregister(City)
|
||||
admin.site.register(City, original_geoadmin.__class__)
|
||||
|
||||
def test_olmap_WMS_rendering(self):
|
||||
geoadmin = admin.GeoModelAdmin(City, admin.site)
|
||||
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
|
||||
|
|
Loading…
Reference in New Issue