Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #9806 -- Allowed editing GeometryField with OpenLayersWidget

Thanks Paul Winkler for the initial patch.
  • Loading branch information...
commit e6f5b7eacd32afb892c486a5b0994f7f11170868 1 parent f3d1aeb
Claude Paroz authored
1  django/contrib/gis/admin/options.py
@@ -94,6 +94,7 @@ class OLMap(self.widget):
94 94
                       'scrollable' : self.scrollable,
95 95
                       'layerswitcher' : self.layerswitcher,
96 96
                       'collection_type' : collection_type,
  97
+                      'is_generic' : db_field.geom_type == 'GEOMETRY',
97 98
                       'is_linestring' : db_field.geom_type in ('LINESTRING', 'MULTILINESTRING'),
98 99
                       'is_polygon' : db_field.geom_type in ('POLYGON', 'MULTIPOLYGON'),
99 100
                       'is_point' : db_field.geom_type in ('POINT', 'MULTIPOINT'),
3  django/contrib/gis/admin/widgets.py
@@ -40,7 +40,8 @@ def render(self, name, value, attrs=None):
40 40
                 )
41 41
                 value = None
42 42
 
43  
-        if value and value.geom_type.upper() != self.geom_type:
  43
+        if (value and value.geom_type.upper() != self.geom_type and
  44
+                self.geom_type != 'GEOMETRY'):
44 45
             value = None
45 46
 
46 47
         # Constructing the dictionary of the map options.
28  django/contrib/gis/templates/gis/admin/openlayers.js
@@ -6,6 +6,7 @@ OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
6 6
 {{ module }}.wkt_f = new OpenLayers.Format.WKT();
7 7
 {{ module }}.is_collection = {{ is_collection|yesno:"true,false" }};
8 8
 {{ module }}.collection_type = '{{ collection_type }}';
  9
+{{ module }}.is_generic = {{ is_generic|yesno:"true,false" }};
9 10
 {{ module }}.is_linestring = {{ is_linestring|yesno:"true,false" }};
10 11
 {{ module }}.is_polygon = {{ is_polygon|yesno:"true,false" }};
11 12
 {{ module }}.is_point = {{ is_point|yesno:"true,false" }};
@@ -89,24 +90,19 @@ OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp
89 90
 // Create an array of controls based on geometry type
90 91
 {{ module }}.getControls = function(lyr){
91 92
   {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'});
92  
-  var nav = new OpenLayers.Control.Navigation();
93  
-  var draw_ctl;
94  
-  if ({{ module }}.is_linestring){
95  
-    draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'});
96  
-  } else if ({{ module }}.is_polygon){
97  
-    draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'});
98  
-  } else if ({{ module }}.is_point){
99  
-    draw_ctl = new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'});
  93
+  {{ module }}.controls = [new OpenLayers.Control.Navigation()];
  94
+  if (!{{ module }}.modifiable && lyr.features.length) return;
  95
+  if ({{ module }}.is_linestring || {{ module }}.is_generic){
  96
+    {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'}));
  97
+  }
  98
+  if ({{ module }}.is_polygon || {{ module }}.is_generic){
  99
+    {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'}));
  100
+  }
  101
+  if ({{ module }}.is_point || {{ module }}.is_generic){
  102
+    {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'}));
100 103
   }
101 104
   if ({{ module }}.modifiable){
102  
-    var mod = new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'});
103  
-    {{ module }}.controls = [nav, draw_ctl, mod];
104  
-  } else {
105  
-    if(!lyr.features.length){
106  
-      {{ module }}.controls = [nav, draw_ctl];
107  
-    } else {
108  
-      {{ module }}.controls = [nav];
109  
-    }
  105
+    {{ module }}.controls.push(new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'}));
110 106
   }
111 107
 };
112 108
 {{ module }}.init = function(){
3  docs/releases/1.6.txt
@@ -134,6 +134,9 @@ Minor features
134 134
 * SimpleLazyObjects will now present more helpful representations in shell
135 135
   debugging situations.
136 136
 
  137
+* Generic :class:`~django.contrib.gis.db.models.GeometryField` is now editable
  138
+  with the OpenLayers widget in the admin.
  139
+
137 140
 Backwards incompatible changes in 1.6
138 141
 =====================================
139 142
 

0 notes on commit e6f5b7e

Please sign in to comment.
Something went wrong with that request. Please try again.