Cleanup based on review comments
This commit is contained in:
parent
1016159f34
commit
31b8faa627
|
@ -1,6 +1,6 @@
|
||||||
from django.db.models.sql.constants import QUERY_TERMS
|
from django.db.models.sql.constants import QUERY_TERMS
|
||||||
|
|
||||||
ALL_TERMS = set([
|
GIS_LOOKUPS = {
|
||||||
'bbcontains', 'bboverlaps', 'contained', 'contains',
|
'bbcontains', 'bboverlaps', 'contained', 'contains',
|
||||||
'contains_properly', 'coveredby', 'covers', 'crosses', 'disjoint',
|
'contains_properly', 'coveredby', 'covers', 'crosses', 'disjoint',
|
||||||
'distance_gt', 'distance_gte', 'distance_lt', 'distance_lte',
|
'distance_gt', 'distance_gte', 'distance_lt', 'distance_lte',
|
||||||
|
@ -9,8 +9,7 @@ ALL_TERMS = set([
|
||||||
'left', 'right', 'overlaps_left', 'overlaps_right',
|
'left', 'right', 'overlaps_left', 'overlaps_right',
|
||||||
'overlaps_above', 'overlaps_below',
|
'overlaps_above', 'overlaps_below',
|
||||||
'strictly_above', 'strictly_below'
|
'strictly_above', 'strictly_below'
|
||||||
])
|
}
|
||||||
GIS_LOOKUPS = ALL_TERMS.copy()
|
ALL_TERMS = GIS_LOOKUPS | QUERY_TERMS
|
||||||
ALL_TERMS.update(QUERY_TERMS)
|
|
||||||
|
|
||||||
__all__ = ['ALL_TERMS', 'GIS_LOOKUPS']
|
__all__ = ['ALL_TERMS', 'GIS_LOOKUPS']
|
||||||
|
|
|
@ -201,16 +201,20 @@ compile_implementations = defaultdict(dict)
|
||||||
|
|
||||||
|
|
||||||
def get_implementations(vendor):
|
def get_implementations(vendor):
|
||||||
try:
|
return compile_implementations[vendor]
|
||||||
implementation = compile_implementations[vendor]
|
|
||||||
except KeyError:
|
|
||||||
# TODO: do we need thread safety here? We could easily use an lock...
|
|
||||||
implementation = {}
|
|
||||||
compile_implementations[vendor] = implementation
|
|
||||||
return implementation
|
|
||||||
|
|
||||||
|
|
||||||
class add_implementation(object):
|
class add_implementation(object):
|
||||||
|
"""
|
||||||
|
A decorator to allow customised implementations for query expressions.
|
||||||
|
For example:
|
||||||
|
@add_implementation(Exact, 'mysql')
|
||||||
|
def mysql_exact(node, qn, connection):
|
||||||
|
# Play with the node here.
|
||||||
|
return somesql, list_of_params
|
||||||
|
Now Exact nodes are compiled to SQL using mysql_exact instead of
|
||||||
|
Exact.as_sql() when using MySQL backend.
|
||||||
|
"""
|
||||||
def __init__(self, klass, vendor):
|
def __init__(self, klass, vendor):
|
||||||
self.klass = klass
|
self.klass = klass
|
||||||
self.vendor = vendor
|
self.vendor = vendor
|
||||||
|
|
Loading…
Reference in New Issue