Kaydet (Commit) 75aeebeb authored tarafından Dylan Verheul's avatar Dylan Verheul Kaydeden (comit) Tim Graham

Fixed #28105 -- Fixed crash in BaseGeometryWidget.get_context() when overriding existing attrs.

üst 1ebd2950
...@@ -63,15 +63,16 @@ class BaseGeometryWidget(Widget): ...@@ -63,15 +63,16 @@ class BaseGeometryWidget(Widget):
if attrs is None: if attrs is None:
attrs = {} attrs = {}
context.update(self.build_attrs(self.attrs, dict( build_attrs_kwargs = {
name=name, 'name': name,
module='geodjango_%s' % name.replace('-', '_'), # JS-safe 'module': 'geodjango_%s' % name.replace('-', '_'), # JS-safe
serialized=self.serialize(value), 'serialized': self.serialize(value),
geom_type=gdal.OGRGeomType(self.attrs['geom_type']), 'geom_type': gdal.OGRGeomType(self.attrs['geom_type']),
STATIC_URL=settings.STATIC_URL, 'STATIC_URL': settings.STATIC_URL,
LANGUAGE_BIDI=translation.get_language_bidi(), 'LANGUAGE_BIDI': translation.get_language_bidi(),
**attrs }
))) build_attrs_kwargs.update(attrs)
context.update(self.build_attrs(self.attrs, build_attrs_kwargs))
return context return context
......
...@@ -66,3 +66,6 @@ Bugfixes ...@@ -66,3 +66,6 @@ Bugfixes
* Updated the ``contrib.postgres`` ``SplitArrayWidget`` to use template-based * Updated the ``contrib.postgres`` ``SplitArrayWidget`` to use template-based
widget rendering (:ticket:`28040`). widget rendering (:ticket:`28040`).
* Fixed crash in ``BaseGeometryWidget.get_context()`` when overriding existing
``attrs`` (:ticket:`28105`).
import re import re
from django.contrib.gis import forms from django.contrib.gis import forms
from django.contrib.gis.forms import BaseGeometryWidget
from django.contrib.gis.geos import GEOSGeometry from django.contrib.gis.geos import GEOSGeometry
from django.forms import ValidationError from django.forms import ValidationError
from django.test import SimpleTestCase, override_settings, skipUnlessDBFeature from django.test import SimpleTestCase, override_settings, skipUnlessDBFeature
...@@ -353,6 +354,12 @@ class OSMWidgetTest(SimpleTestCase): ...@@ -353,6 +354,12 @@ class OSMWidgetTest(SimpleTestCase):
@skipUnlessDBFeature("gis_enabled") @skipUnlessDBFeature("gis_enabled")
class GeometryWidgetTests(SimpleTestCase): class GeometryWidgetTests(SimpleTestCase):
def test_get_context_attrs(self):
"""The Widget.get_context() attrs argument overrides self.attrs."""
widget = BaseGeometryWidget(attrs={'geom_type': 'POINT'})
context = widget.get_context('point', None, attrs={'geom_type': 'POINT2'})
self.assertEqual(context['geom_type'], 'POINT2')
def test_subwidgets(self): def test_subwidgets(self):
widget = forms.BaseGeometryWidget() widget = forms.BaseGeometryWidget()
self.assertEqual( self.assertEqual(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment