[Django] #25448: Ease creation of custom GIS lookups

19 views
Skip to first unread message

Django

unread,
Sep 22, 2015, 3:38:52 PM9/22/15
to django-...@googlegroups.com
#25448: Ease creation of custom GIS lookups
------------------------------------------------+------------------------
Reporter: claudep | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: GIS | Version: master
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/25448>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 22, 2015, 3:43:26 PM9/22/15
to django-...@googlegroups.com
#25448: Ease creation of custom GIS lookups
--------------------------------------+------------------------------------

Reporter: claudep | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

Planned modification (to be tested):
{{{
#!diff
diff --git a/django/contrib/gis/db/models/lookups.py
b/django/contrib/gis/db/models/lookups.py
index 46104a2..33fa635 100644
--- a/django/contrib/gis/db/models/lookups.py
+++ b/django/contrib/gis/db/models/lookups.py
@@ -93,7 +93,7 @@ class GISLookup(Lookup):
sql_params.extend(rhs_params)

template_params = {'lhs': lhs_sql, 'rhs': rhs_sql}
- backend_op = connection.ops.gis_operators[self.lookup_name]
+ backend_op = connection.ops.gis_operators.get(self.lookup_name,
self.lookup_name)
return backend_op.as_sql(connection, self, template_params,
sql_params)


}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25448#comment:1>

Django

unread,
Sep 22, 2015, 3:49:38 PM9/22/15
to django-...@googlegroups.com
#25448: Ease creation of custom GIS lookups
--------------------------------------+------------------------------------

Reporter: claudep | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by claudep):

Planned feature (to be tested):


{{{
#!diff
diff --git a/django/contrib/gis/db/models/lookups.py
b/django/contrib/gis/db/models/lookups.py

index 46104a2..ed993ca 100644
--- a/django/contrib/gis/db/models/lookups.py
+++ b/django/contrib/gis/db/models/lookups.py
@@ -87,13 +87,16 @@ class GISLookup(Lookup):
rhs = connection.ops.get_geom_placeholder(self.lhs.output_field,
geom, compiler)
return rhs, rhs_params

+ def get_operator(connection):
+ return connection.ops.gis_operators.get[self.lookup_name]
+
def as_sql(self, compiler, connection):
lhs_sql, sql_params = self.process_lhs(compiler, connection)
rhs_sql, rhs_params = self.process_rhs(compiler, connection)
sql_params.extend(rhs_params)

template_params = {'lhs': lhs_sql, 'rhs': rhs_sql}
- backend_op = connection.ops.gis_operators[self.lookup_name]

+ backend_op = self.get_operator(connection)


return backend_op.as_sql(connection, self, template_params,
sql_params)


}}}

Django

unread,
Sep 23, 2015, 3:31:54 AM9/23/15
to django-...@googlegroups.com
#25448: Ease creation of custom GIS lookups
--------------------------------------+------------------------------------

Reporter: claudep | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by claudep):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25448#comment:2>

Django

unread,
Sep 23, 2015, 1:36:02 PM9/23/15
to django-...@googlegroups.com
#25448: Ease creation of custom GIS lookups
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: GIS | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/25448#comment:3>

Django

unread,
Sep 23, 2015, 4:03:44 PM9/23/15
to django-...@googlegroups.com
#25448: Ease creation of custom GIS lookups
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: GIS | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"c9a02bc8f5114d95079f72dd22aaeec36899117e" c9a02bc8]:
{{{
#!CommitTicketReference repository=""
revision="c9a02bc8f5114d95079f72dd22aaeec36899117e"
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).
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25448#comment:4>

Reply all
Reply to author
Forward
0 new messages