yourcelf / olwidget

Javascript library to replace textareas that contain WKT data with editable OpenLayers maps, and a django app using it for django forms and admin.
Other
91 stars 43 forks source link

v0.3 EditableMap Widget _has_changed() method does not work [incl. Patch] #41

Closed tspng closed 13 years ago

tspng commented 14 years ago

Hi,

I' just noticed a bug in v0.3 (didn't check multi branch, maybe there is the same problem) which results in admin log changed entires for all geometry types, whether they have been changed or not.

The problem is, that the inherited _has_changed() method from TextArea does not work because the initial data is a geometry object and the form data is a string in EWKT format.

Here's a proposed patch for it. I'm not quite sure if it's the correct way to do it but it works in my case:

diff -u -r old/src/django-olwidget/django-olwidget/olwidget/widgets.py new/src/django-olwidget/django-olwidget/olwidget/widgets.py
--- old/src/django-olwidget/django-olwidget/olwidget/widgets.py 2010-07-01 11:25:03.000000000 +0200
+++ new/src/django-olwidget/django-olwidget/olwidget/widgets.py 2010-07-01 11:21:35.000000000 +0200
@@ -131,6 +131,10 @@
         }
         return render_to_string(self.template, context)

+    def _has_changed(self, initial, data):
+        # make sure initial and data are strings in EWKT format and then let TextArea widget do the comparison.
+        return super(EditableMap, self)._has_changed(add_srid(get_wkt(initial)), data)
+
 class MapDisplay(EditableMap):
     """
     Object for display of geometries on an OpenLayers map.  Arguments (all are
yourcelf commented 13 years ago

This is fixed in v0.4.