Commit 49194df8 authored by Justin Bronn's avatar Justin Bronn
Browse files

[1.1.X] Fixed #11353 -- `GeometryProxy` descriptor no longer chokes when...

[1.1.X] Fixed #11353 -- `GeometryProxy` descriptor no longer chokes when accessed from a class rather than an instance, thanks yml and Tobu; removed unnecessary imports from `types` and cleaned up whitespace.

Backport of r12584 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12585 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 40064025
Loading
Loading
Loading
Loading
+27 −25
Original line number Diff line number Diff line
@@ -6,8 +6,6 @@
Thanks to Robert Coup for providing this functionality (see #4322).
"""

from types import NoneType, StringType, UnicodeType

class GeometryProxy(object):
    def __init__(self, klass, field):
        """
@@ -23,6 +21,10 @@ class GeometryProxy(object):
        class specified during initialization and the HEXEWKB value of the field.
        Currently, only GEOS or OGR geometries are supported.
        """
        if obj is None:
            # Accessed on a class, not an instance
            return self

        # Getting the value of the field.
        geom_value = obj.__dict__[self._field.attname]

@@ -51,8 +53,8 @@ class GeometryProxy(object):
        if isinstance(value, self._klass) and (str(value.geom_type).upper() == gtype or gtype == 'GEOMETRY'):
            # Assigning the SRID to the geometry.
            if value.srid is None: value.srid = self._field.srid
        elif isinstance(value, (NoneType, StringType, UnicodeType)):
            # Set with None, WKT, or HEX
        elif value is None or isinstance(value, (basestring, buffer)):
            # Set with None, WKT, HEX, or WKB
            pass
        else:
            raise TypeError('cannot set %s GeometryProxy with value of type: %s' % (obj.__class__.__name__, type(value)))