0
0
mirror of https://github.com/django/django.git synced 2024-11-22 03:18:31 +01:00

Fixed #21021 -- Changed BaseGeometryWidget's default geometry type to 'Geometry'.

This commit is contained in:
Giannis Adamopoulos 2020-11-26 00:36:35 +02:00 committed by Mariusz Felisiak
parent 9175a2cc32
commit 7603036bd0
3 changed files with 7 additions and 2 deletions

View File

@ -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 {}),

View File

@ -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});

View File

@ -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()