Cleanup based on review comments

This commit is contained in:
Anssi Kääriäinen 2013-12-29 15:52:29 +02:00
parent 1016159f34
commit 31b8faa627
2 changed files with 14 additions and 11 deletions

View File

@ -1,6 +1,6 @@
from django.db.models.sql.constants import QUERY_TERMS
ALL_TERMS = set([
GIS_LOOKUPS = {
'bbcontains', 'bboverlaps', 'contained', 'contains',
'contains_properly', 'coveredby', 'covers', 'crosses', 'disjoint',
'distance_gt', 'distance_gte', 'distance_lt', 'distance_lte',
@ -9,8 +9,7 @@ ALL_TERMS = set([
'left', 'right', 'overlaps_left', 'overlaps_right',
'overlaps_above', 'overlaps_below',
'strictly_above', 'strictly_below'
])
GIS_LOOKUPS = ALL_TERMS.copy()
ALL_TERMS.update(QUERY_TERMS)
}
ALL_TERMS = GIS_LOOKUPS | QUERY_TERMS
__all__ = ['ALL_TERMS', 'GIS_LOOKUPS']

View File

@ -201,16 +201,20 @@ compile_implementations = defaultdict(dict)
def get_implementations(vendor):
try:
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
return compile_implementations[vendor]
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):
self.klass = klass
self.vendor = vendor