Opened 9 years ago

Closed 9 years ago

#25448 closed Cleanup/optimization (fixed)

Ease creation of custom GIS lookups

Reported by: Claude Paroz Owned by: nobody
Component: GIS Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Following the use case described in #25446, the current GISLookup class is missing a small change to allow an easy definition of custom lookups.
I plan to offer a patch soon.

Change History (4)

comment:1 by Claude Paroz, 9 years ago

Planned feature (to be tested):

  • django/contrib/gis/db/models/lookups.py

    diff --git a/django/contrib/gis/db/models/lookups.py b/django/contrib/gis/db/models/lookups.py
    index 46104a2..ed993ca 100644
    a b class GISLookup(Lookup):  
    8787        rhs = connection.ops.get_geom_placeholder(self.lhs.output_field, geom, compiler)
    8888        return rhs, rhs_params
    8989
     90    def get_operator(connection):
     91        return connection.ops.gis_operators.get[self.lookup_name]
     92
    9093    def as_sql(self, compiler, connection):
    9194        lhs_sql, sql_params = self.process_lhs(compiler, connection)
    9295        rhs_sql, rhs_params = self.process_rhs(compiler, connection)
    9396        sql_params.extend(rhs_params)
    9497
    9598        template_params = {'lhs': lhs_sql, 'rhs': rhs_sql}
    96         backend_op = connection.ops.gis_operators[self.lookup_name]
     99        backend_op = self.get_operator(connection)
    97100        return backend_op.as_sql(connection, self, template_params, sql_params)
    98101
    99102

comment:2 by Claude Paroz, 9 years ago

Has patch: set

comment:3 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: newclosed

In c9a02bc8:

Fixed #25448 -- Eased GISLookup subclassing with custom lookups

When someone needs to build a custom backend-specific GIS lookup, it
is much easier done if getting the spatial operator class happens in
a dedicated method (no need to rewrite the entire as_sql() method).

Note: See TracTickets for help on using tickets.
Back to Top