diff options
| author | Tim Graham <timograham@gmail.com> | 2017-04-20 11:36:40 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-04-20 11:40:20 -0400 |
| commit | 5e2bbcd70c9b0213bfda31b90e4b1c35815880e9 (patch) | |
| tree | acfc13936a1bf478d64fe3869d1a16e0f37abc87 | |
| parent | 0d9e7e9a262644d9f89d9d3a7c443be0e88c2188 (diff) | |
[1.11.x] Fixed #28039 -- Fixed crash in BaseGeometryWidget.subwidgets().
Backport of d2cb7a2bc11f111be04a29b5e4f92a183b18ba88 from master
| -rw-r--r-- | django/contrib/gis/forms/widgets.py | 5 | ||||
| -rw-r--r-- | docs/releases/1.11.1.txt | 2 | ||||
| -rw-r--r-- | tests/gis_tests/test_geoforms.py | 22 |
3 files changed, 26 insertions, 3 deletions
diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py index e9518f4e7e..cc82f41563 100644 --- a/django/contrib/gis/forms/widgets.py +++ b/django/contrib/gis/forms/widgets.py @@ -43,6 +43,7 @@ class BaseGeometryWidget(Widget): return None def get_context(self, name, value, attrs): + context = super(BaseGeometryWidget, self).get_context(name, value, attrs) # If a string reaches here (via a validation error on another # field) then just reconstruct the Geometry. if value and isinstance(value, six.string_types): @@ -64,7 +65,7 @@ class BaseGeometryWidget(Widget): if attrs is None: attrs = {} - context = self.build_attrs(self.attrs, dict( + context.update(self.build_attrs(self.attrs, dict( name=name, module='geodjango_%s' % name.replace('-', '_'), # JS-safe serialized=self.serialize(value), @@ -72,7 +73,7 @@ class BaseGeometryWidget(Widget): STATIC_URL=settings.STATIC_URL, LANGUAGE_BIDI=translation.get_language_bidi(), **attrs - )) + ))) return context diff --git a/docs/releases/1.11.1.txt b/docs/releases/1.11.1.txt index 53c43443aa..1f475ee736 100644 --- a/docs/releases/1.11.1.txt +++ b/docs/releases/1.11.1.txt @@ -40,3 +40,5 @@ Bugfixes * Restored the output of the ``class`` attribute in the ``<ul>`` of widgets that use the ``multiple_input.html`` template. This fixes ``ModelAdmin.radio_fields`` with ``admin.HORIZONTAL`` (:ticket:`28059`). + +* Fixed crash in ``BaseGeometryWidget.subwidgets()`` (:ticket:`28039`). diff --git a/tests/gis_tests/test_geoforms.py b/tests/gis_tests/test_geoforms.py index 437a828e47..7bec54edf5 100644 --- a/tests/gis_tests/test_geoforms.py +++ b/tests/gis_tests/test_geoforms.py @@ -351,7 +351,27 @@ class OSMWidgetTest(SimpleTestCase): @skipUnlessDBFeature("gis_enabled") -class CustomGeometryWidgetTest(SimpleTestCase): +class GeometryWidgetTests(SimpleTestCase): + + def test_subwidgets(self): + widget = forms.BaseGeometryWidget() + self.assertEqual( + list(widget.subwidgets('name', 'value')), + [{ + 'is_hidden': False, + 'attrs': { + 'map_srid': 4326, + 'map_width': 600, + 'geom_type': 'GEOMETRY', + 'map_height': 400, + 'display_raw': False, + }, + 'name': 'name', + 'template_name': '', + 'value': 'value', + 'required': False, + }] + ) def test_custom_serialization_widget(self): class CustomGeometryWidget(forms.BaseGeometryWidget): |
