summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-03-09 16:01:33 +0100
committerClaude Paroz <claude@2xlibre.net>2013-03-09 16:10:28 +0100
commite6f5b7eacd32afb892c486a5b0994f7f11170868 (patch)
tree77b45033c8a29c3489db590d5c1d215ae3922874
parentf3d1aebed1f72fc150e03aba18cc5bc56de6f5c4 (diff)
Fixed #9806 -- Allowed editing GeometryField with OpenLayersWidget
Thanks Paul Winkler for the initial patch.
-rw-r--r--django/contrib/gis/admin/options.py1
-rw-r--r--django/contrib/gis/admin/widgets.py3
-rw-r--r--django/contrib/gis/templates/gis/admin/openlayers.js28
-rw-r--r--docs/releases/1.6.txt3
4 files changed, 18 insertions, 17 deletions
diff --git a/django/contrib/gis/admin/options.py b/django/contrib/gis/admin/options.py
index 6bdceb7722..7e79be1860 100644
--- a/django/contrib/gis/admin/options.py
+++ b/django/contrib/gis/admin/options.py
@@ -94,6 +94,7 @@ class GeoModelAdmin(ModelAdmin):
'scrollable' : self.scrollable,
'layerswitcher' : self.layerswitcher,
'collection_type' : collection_type,
+ 'is_generic' : db_field.geom_type == 'GEOMETRY',
'is_linestring' : db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'),
'is_polygon' : db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'),
'is_point' : db_field.geom_type in ('POINT', 'MULTIPOINT'),
diff --git a/django/contrib/gis/admin/widgets.py b/django/contrib/gis/admin/widgets.py
index a06933660f..ceb8e9c9bd 100644
--- a/django/contrib/gis/admin/widgets.py
+++ b/django/contrib/gis/admin/widgets.py
@@ -40,7 +40,8 @@ class OpenLayersWidget(Textarea):
)
value = None
- if value and value.geom_type.upper() != self.geom_type:
+ if (value and value.geom_type.upper() != self.geom_type and
+ self.geom_type != 'GEOMETRY'):
value = None
# Constructing the dictionary of the map options.
diff --git a/django/contrib/gis/templates/gis/admin/openlayers.js b/django/contrib/gis/templates/gis/admin/openlayers.js
index 19b9192950..924621ea49 100644
--- a/django/contrib/gis/templates/gis/admin/openlayers.js
+++ b/django/contrib/gis/templates/gis/admin/openlayers.js
@@ -6,6 +6,7 @@ OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
{{ module }}.wkt_f = new OpenLayers.Format.WKT();
{{ module }}.is_collection = {{ is_collection|yesno:"true,false" }};
{{ module }}.collection_type = '{{ collection_type }}';
+{{ module }}.is_generic = {{ is_generic|yesno:"true,false" }};
{{ module }}.is_linestring = {{ is_linestring|yesno:"true,false" }};
{{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }};
{{ module }}.is_point = {{ is_point|yesno:"true,false" }};
@@ -89,24 +90,19 @@ OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
// Create an array of controls based on geometry type
{{ module }}.getControls = function(lyr){
{{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'});
- var nav = new OpenLayers.Control.Navigation();
- var draw_ctl;
- if ({{ module }}.is_linestring){
- draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'});
- } else if ({{ module }}.is_polygon){
- draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'});
- } else if ({{ module }}.is_point){
- draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'});
+ {{ module }}.controls = [new OpenLayers.Control.Navigation()];
+ if (!{{ module }}.modifiable && lyr.features.length) return;
+ if ({{ module }}.is_linestring || {{ module }}.is_generic){
+ {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}));
+ }
+ if ({{ module }}.is_polygon || {{ module }}.is_generic){
+ {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}));
+ }
+ if ({{ module }}.is_point || {{ module }}.is_generic){
+ {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}));
}
if ({{ module }}.modifiable){
- var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'});
- {{ module }}.controls = [nav, draw_ctl, mod];
- } else {
- if(!lyr.features.length){
- {{ module }}.controls = [nav, draw_ctl];
- } else {
- {{ module }}.controls = [nav];
- }
+ {{ module }}.controls.push(new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}));
}
};
{{ module }}.init = function(){
diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt
index c8012ab7c2..dd7a9a463e 100644
--- a/docs/releases/1.6.txt
+++ b/docs/releases/1.6.txt
@@ -134,6 +134,9 @@ Minor features
* SimpleLazyObjects will now present more helpful representations in shell
debugging situations.
+* Generic :class:`~django.contrib.gis.db.models.GeometryField` is now editable
+ with the OpenLayers widget in the admin.
+
Backwards incompatible changes in 1.6
=====================================