Commit ea27e26b authored by Claude Paroz's avatar Claude Paroz
Browse files

Deprecated legacy GeoManager/GeoQuerySet methods

parent 71e20814
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
import warnings

from django.contrib.gis.db.models.query import GeoQuerySet
from django.db.models.manager import Manager
from django.utils.deprecation import RemovedInDjango21Warning


class GeoManager(Manager.from_queryset(GeoQuerySet)):
@@ -9,3 +12,11 @@ class GeoManager(Manager.from_queryset(GeoQuerySet)):
    # so that geometry columns on Oracle and MySQL are selected
    # properly.
    use_for_related_fields = True

    def __init__(self, *args, **kwargs):
        warnings.warn(
            "The GeoManager class is deprecated. Simply use a normal manager "
            "once you have replaced all calls to GeoQuerySet methods by annotations.",
            RemovedInDjango21Warning, stacklevel=2
        )
        super(GeoManager, self).__init__(*args, **kwargs)
+8 −1
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@ from django.db.models.expressions import RawSQL
from django.db.models.fields import Field
from django.db.models.query import QuerySet
from django.utils import six
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.deprecation import (
    RemovedInDjango20Warning, RemovedInDjango21Warning,
)


class GeoQuerySet(QuerySet):
@@ -513,6 +515,11 @@ class GeoQuerySet(QuerySet):
          The name of the model attribute to attach the output of
          the spatial function to.
        """
        warnings.warn(
            "The %s GeoQuerySet method is deprecated. See GeoDjango Functions "
            "documentation to find the expression-based replacement." % att,
            RemovedInDjango21Warning, stacklevel=2
        )
        # Default settings.
        settings.setdefault('desc', None)
        settings.setdefault('geom_args', ())
+7 −4
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ from __future__ import unicode_literals

from django.apps import apps
from django.contrib.gis.db.models.fields import GeometryField
from django.contrib.gis.db.models.functions import AsKML, Transform
from django.contrib.gis.shortcuts import render_to_kml, render_to_kmz
from django.core.exceptions import FieldDoesNotExist
from django.db import DEFAULT_DB_ALIAS, connections
@@ -31,15 +32,17 @@ def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB

    connection = connections[using]

    if connection.features.has_kml_method:
    if connection.features.has_AsKML_function:
        # Database will take care of transformation.
        placemarks = klass._default_manager.using(using).kml(field_name=field_name)
        placemarks = klass._default_manager.using(using).annotate(kml=AsKML(field_name))
    else:
        # If the database offers no KML method, we use the `kml`
        # attribute of the lazy geometry instead.
        placemarks = []
        if connection.features.has_transform_method:
            qs = klass._default_manager.using(using).transform(4326, field_name=field_name)
        if connection.features.has_Transform_function:
            qs = klass._default_manager.using(using).annotate(
                **{'%s_4326' % field_name: Transform(field_name, 4326)})
            field_name += '_4326'
        else:
            qs = klass._default_manager.using(using).all()
        for mod in qs:
+2 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ details on these changes.
* The ``django.contrib.auth.tests.utils.skipIfCustomUser()`` decorator will be
  removed.

* The ``GeoManager`` and ``GeoQuerySet`` classes will be removed.

.. _deprecation-removed-in-2.0:

2.0
+10 −0
Original line number Diff line number Diff line
@@ -400,6 +400,16 @@ of its methods and attributes are either changed or renamed.

The aim of these changes is to provide a documented API for relation fields.

``GeoManager`` and ``GeoQuerySet`` custom methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All custom ``GeoQuerySet`` methods (``area()``, ``distance()``, ``gml()``, ...)
have been replaced by equivalent geographic expressions in annotations (see in
new features). Hence the need to set a custom ``GeoManager`` to GIS-enabled
models is now obsolete. As soon as your code doesn't call any of the deprecated
methods, you can simply remove the ``objects = GeoManager()`` lines from your
models.

Miscellaneous
~~~~~~~~~~~~~

Loading