diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py index 611bed9f6d..e38f173a98 100644 --- a/django/contrib/gis/forms/widgets.py +++ b/django/contrib/gis/forms/widgets.py @@ -61,11 +61,12 @@ class BaseGeometryWidget(Widget): value.srid, self.map_srid, err ) + geom_type = gdal.OGRGeomType(self.attrs['geom_type']).name context.update(self.build_attrs(self.attrs, { 'name': name, 'module': 'geodjango_%s' % name.replace('-', '_'), # JS-safe 'serialized': self.serialize(value), - 'geom_type': gdal.OGRGeomType(self.attrs['geom_type']), + 'geom_type': 'Geometry' if geom_type == 'Unknown' else geom_type, 'STATIC_URL': settings.STATIC_URL, 'LANGUAGE_BIDI': translation.get_language_bidi(), **(attrs or {}), diff --git a/django/contrib/gis/static/gis/js/OLMapWidget.js b/django/contrib/gis/static/gis/js/OLMapWidget.js index 8c1d7feede..29725636a3 100644 --- a/django/contrib/gis/static/gis/js/OLMapWidget.js +++ b/django/contrib/gis/static/gis/js/OLMapWidget.js @@ -133,7 +133,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control); // Initialize the draw interaction let geomType = this.options.geom_name; - if (geomType === "Unknown" || geomType === "GeometryCollection") { + if (geomType === "Geometry" || geomType === "GeometryCollection") { // Default to Point, but create icons to switch type geomType = "Point"; this.currentGeometryType = new GeometryTypeControl({widget: this, type: "Point", active: true}); diff --git a/tests/gis_tests/test_geoforms.py b/tests/gis_tests/test_geoforms.py index 74c082e59d..93cf5be20b 100644 --- a/tests/gis_tests/test_geoforms.py +++ b/tests/gis_tests/test_geoforms.py @@ -382,6 +382,10 @@ class GeometryWidgetTests(SimpleTestCase): widget = BaseGeometryWidget(attrs={'geom_type': 'POLYGON'}) context = widget.get_context('polygon', None, None) self.assertEqual(context['geom_type'], 'Polygon') + # Widget.get_context() returns 'Geometry' instead of 'Unknown'. + widget = BaseGeometryWidget(attrs={'geom_type': 'GEOMETRY'}) + context = widget.get_context('geometry', None, None) + self.assertEqual(context['geom_type'], 'Geometry') def test_subwidgets(self): widget = forms.BaseGeometryWidget()