Commit 32d4db66 authored by Marc Tamlyn's avatar Marc Tamlyn
Browse files

Update converters to take a consistent set of parameters.

As suggested by Anssi. This has the slightly strange side effect of
passing the expression to Expression.convert_value has the expression
passed back to it, but it allows more complex patterns of expressions.
parent 4755f8fc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ class OracleOperations(BaseSpatialOperations, DatabaseOperations):
            converters.append(self.convert_geometry)
        return converters

    def convert_geometry(self, value, expression, context):
    def convert_geometry(self, value, expression, connection, context):
        if value:
            value = Geometry(value)
            if 'transformed_srid' in context:
+1 −1
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ class SpatiaLiteOperations(BaseSpatialOperations, DatabaseOperations):
            converters.append(self.convert_geometry)
        return converters

    def convert_geometry(self, value, expression, context):
    def convert_geometry(self, value, expression, connection, context):
        if value:
            value = Geometry(value)
            if 'transformed_srid' in context:
+3 −3
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class GeoAggregate(Aggregate):
            raise ValueError('Geospatial aggregates only allowed on geometry fields.')
        return c

    def convert_value(self, value, connection, context):
    def convert_value(self, value, expression, connection, context):
        return connection.ops.convert_geom(value, self.output_field)


@@ -44,7 +44,7 @@ class Extent(GeoAggregate):
    def __init__(self, expression, **extra):
        super(Extent, self).__init__(expression, output_field=ExtentField(), **extra)

    def convert_value(self, value, connection, context):
    def convert_value(self, value, expression, connection, context):
        return connection.ops.convert_extent(value, context.get('transformed_srid'))


@@ -55,7 +55,7 @@ class Extent3D(GeoAggregate):
    def __init__(self, expression, **extra):
        super(Extent3D, self).__init__(expression, output_field=ExtentField(), **extra)

    def convert_value(self, value, connection, context):
    def convert_value(self, value, expression, connection, context):
        return connection.ops.convert_extent3d(value, context.get('transformed_srid'))


+1 −1
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ class GeometryField(GeoSelectFormatMixin, Field):
        else:
            return geom

    def from_db_value(self, value, connection, context):
    def from_db_value(self, value, expression, connection, context):
        if value and not isinstance(value, Geometry):
            value = Geometry(value)
        return value
+4 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ class AreaField(BaseField):
    def __init__(self, area_att):
        self.area_att = area_att

    def from_db_value(self, value, connection, context):
    def from_db_value(self, value, expression, connection, context):
        if value is not None:
            value = Area(**{self.area_att: value})
        return value
@@ -37,7 +37,7 @@ class DistanceField(BaseField):
    def __init__(self, distance_att):
        self.distance_att = distance_att

    def from_db_value(self, value, connection, context):
    def from_db_value(self, value, expression, connection, context):
        if value is not None:
            value = Distance(**{self.distance_att: value})
        return value
@@ -54,7 +54,7 @@ class GeomField(GeoSelectFormatMixin, BaseField):
    # Hacky marker for get_db_converters()
    geom_type = None

    def from_db_value(self, value, connection, context):
    def from_db_value(self, value, expression, connection, context):
        if value is not None:
            value = Geometry(value)
        return value
@@ -71,5 +71,5 @@ class GMLField(BaseField):
    def get_internal_type(self):
        return 'GMLField'

    def from_db_value(self, value, connection, context):
    def from_db_value(self, value, expression, connection, context):
        return value
Loading