Fixed #28039 -- Fixed crash in BaseGeometryWidget.subwidgets().
This commit is contained in:
parent
6d7cbe67f0
commit
d2cb7a2bc1
|
@ -41,6 +41,7 @@ class BaseGeometryWidget(Widget):
|
|||
return None
|
||||
|
||||
def get_context(self, name, value, attrs):
|
||||
context = super().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, str):
|
||||
|
@ -62,7 +63,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),
|
||||
|
@ -70,7 +71,7 @@ class BaseGeometryWidget(Widget):
|
|||
STATIC_URL=settings.STATIC_URL,
|
||||
LANGUAGE_BIDI=translation.get_language_bidi(),
|
||||
**attrs
|
||||
))
|
||||
)))
|
||||
return context
|
||||
|
||||
|
||||
|
|
|
@ -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`).
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue