From 31b8faa62714b4b6b6057a9f5cc106c4dd73caab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sun, 29 Dec 2013 15:52:29 +0200 Subject: [PATCH] Cleanup based on review comments --- django/contrib/gis/db/models/constants.py | 7 +++---- django/db/backends/utils.py | 18 +++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/django/contrib/gis/db/models/constants.py b/django/contrib/gis/db/models/constants.py index 52794231b0..4ece41415c 100644 --- a/django/contrib/gis/db/models/constants.py +++ b/django/contrib/gis/db/models/constants.py @@ -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'] diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py index e1a6d76272..2610228085 100644 --- a/django/db/backends/utils.py +++ b/django/db/backends/utils.py @@ -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