diff --git a/django/contrib/gis/admin/__init__.py b/django/contrib/gis/admin/__init__.py index d5bd54c479..2c3de6f4c5 100644 --- a/django/contrib/gis/admin/__init__.py +++ b/django/contrib/gis/admin/__init__.py @@ -27,8 +27,8 @@ __all__ = [ "register", "site", "GISModelAdmin", - "OpenLayersWidget", # RemovedInDjango50Warning. "GeoModelAdmin", + "OpenLayersWidget", "OSMGeoAdmin", ] diff --git a/django/contrib/gis/admin/widgets.py b/django/contrib/gis/admin/widgets.py index 420c170608..9ba262aaf8 100644 --- a/django/contrib/gis/admin/widgets.py +++ b/django/contrib/gis/admin/widgets.py @@ -1,9 +1,12 @@ +# RemovedInDjango50Warning. import logging +import warnings from django.contrib.gis.gdal import GDALException from django.contrib.gis.geos import GEOSException, GEOSGeometry from django.forms.widgets import Textarea from django.utils import translation +from django.utils.deprecation import RemovedInDjango50Warning # Creating a template context that contains Django settings # values needed by admin map templates. @@ -16,6 +19,14 @@ class OpenLayersWidget(Textarea): Render an OpenLayers map using the WKT of the geometry. """ + def __init__(self, *args, **kwargs): + warnings.warn( + "django.contrib.gis.admin.OpenLayersWidget is deprecated.", + RemovedInDjango50Warning, + stacklevel=2, + ) + super().__init__(*args, **kwargs) + def get_context(self, name, value, attrs): # Update the template parameters with any attributes passed in. if attrs: diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index eb6d7f7b2f..903f2f7161 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -101,6 +101,8 @@ details on these changes. ``SimpleTestCase.assertFormError()`` and ``assertFormsetError()`` will no longer be allowed. +* The ``django.contrib.gis.admin.OpenLayersWidget`` will be removed. + .. _deprecation-removed-in-4.1: 4.1 diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index 2c01efbfdd..0de527447b 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -610,6 +610,8 @@ Miscellaneous or pass the form/formset object directly instead. +* The undocumented ``django.contrib.gis.admin.OpenLayersWidget`` is deprecated. + Features removed in 4.1 ======================= diff --git a/tests/gis_tests/geoadmin_deprecated/tests.py b/tests/gis_tests/geoadmin_deprecated/tests.py index dd3e3af069..d6bea7a690 100644 --- a/tests/gis_tests/geoadmin_deprecated/tests.py +++ b/tests/gis_tests/geoadmin_deprecated/tests.py @@ -125,3 +125,8 @@ class DeprecationTests(SimpleTestCase): DeprecatedOSMGeoAdmin(City, site) with self.assertRaisesMessage(RemovedInDjango50Warning, msg): DeprecatedGeoModelAdmin(City, site) + + def test_openlayerswidget_warning(self): + msg = "django.contrib.gis.admin.OpenLayersWidget is deprecated." + with self.assertRaisesMessage(RemovedInDjango50Warning, msg): + admin.OpenLayersWidget()