Fixed #19139 -- Made OpenLayersWidget follow GeoModelAdmin's modifiable attribute

Thanks Tim Graham for the review.
This commit is contained in:
Flavio Curella 2014-08-04 11:14:45 -05:00 committed by Claude Paroz
parent 66580fe97c
commit ce078ef976
4 changed files with 32 additions and 3 deletions

View File

@ -22,6 +22,9 @@ class OpenLayersWidget(Textarea):
# Update the template parameters with any attributes passed in. # Update the template parameters with any attributes passed in.
if attrs: if attrs:
self.params.update(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 # Defaulting the WKT value to a blank string -- this
# will be tested in the JavaScript and the appropriate # will be tested in the JavaScript and the appropriate

View File

@ -31,7 +31,9 @@
//]]> //]]>
</script> </script>
<div id="{{ id }}_map"{% if LANGUAGE_BIDI %} dir="ltr"{% endif %}></div> <div id="{{ id }}_map"{% if LANGUAGE_BIDI %} dir="ltr"{% endif %}></div>
{% if editable %}
<a href="javascript:{{ module }}.clearFeatures()">Delete all Features</a> <a href="javascript:{{ module }}.clearFeatures()">Delete all Features</a>
{% endif %}
{% if display_wkt %}<p> WKT debugging window:</p>{% endif %} {% if display_wkt %}<p> WKT debugging window:</p>{% endif %}
<textarea id="{{ id }}" class="vWKTField required" cols="150" rows="10" name="{{ name }}">{{ wkt }}</textarea> <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> <script type="text/javascript">{% block init_function %}{{ module }}.init();{% endblock %}</script>

View File

@ -0,0 +1,5 @@
from django.contrib.gis import admin
class UnmodifiableAdmin(admin.OSMGeoAdmin):
modifiable = False

View File

@ -7,6 +7,7 @@ if HAS_GEOS:
from django.contrib.gis import admin from django.contrib.gis import admin
from django.contrib.gis.geos import Point from django.contrib.gis.geos import Point
from .admin import UnmodifiableAdmin
from .models import City from .models import City
@ -20,13 +21,31 @@ class GeoAdminTest(TestCase):
self.assertTrue(any(geoadmin.openlayers_url in js for js in admin_js)) self.assertTrue(any(geoadmin.openlayers_url in js for js in admin_js))
def test_olmap_OSM_rendering(self): def test_olmap_OSM_rendering(self):
geoadmin = admin.site._registry[City] delete_all_btn = """<a href="javascript:geodjango_point.clearFeatures()">Delete all Features</a>"""
result = geoadmin.get_map_widget(City._meta.get_field('point'))(
).render('point', Point(-79.460734, 40.18476)) 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( self.assertIn(
"""geodjango_point.layers.base = new OpenLayers.Layer.OSM("OpenStreetMap (Mapnik)");""", """geodjango_point.layers.base = new OpenLayers.Layer.OSM("OpenStreetMap (Mapnik)");""",
result) 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): def test_olmap_WMS_rendering(self):
geoadmin = admin.GeoModelAdmin(City, admin.site) geoadmin = admin.GeoModelAdmin(City, admin.site)
result = geoadmin.get_map_widget(City._meta.get_field('point'))( result = geoadmin.get_map_widget(City._meta.get_field('point'))(