From b99c8d83c972786c6fcd0e84c9e5cb08c1368300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sat, 21 Dec 2013 23:06:29 +0200 Subject: [PATCH] Fixed review notes by Loic --- django/db/backends/utils.py | 3 ++- django/db/models/aggregates.py | 7 +++--- django/db/models/lookups.py | 40 +++++++++++++++++----------------- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py index a1c9f6ec08..e1a6d76272 100644 --- a/django/db/backends/utils.py +++ b/django/db/backends/utils.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +from collections import defaultdict import datetime import decimal import hashlib @@ -196,7 +197,7 @@ def format_number(value, max_digits, decimal_places): return "%.*f" % (decimal_places, value) # Map of vendor name -> map of query element class -> implementation function -compile_implementations = {} +compile_implementations = defaultdict(dict) def get_implementations(vendor): diff --git a/django/db/models/aggregates.py b/django/db/models/aggregates.py index d663e40f26..e31d228aa5 100644 --- a/django/db/models/aggregates.py +++ b/django/db/models/aggregates.py @@ -15,9 +15,10 @@ def refs_aggregate(lookup_parts, aggregates): default annotation names we must check each prefix of the lookup_parts for match. """ - for i in range(len(lookup_parts) + 1): - if LOOKUP_SEP.join(lookup_parts[0:i]) in aggregates: - return aggregates[LOOKUP_SEP.join(lookup_parts[0:i])], lookup_parts[i:] + for n in range(len(lookup_parts) + 1): + level_n_lookup = LOOKUP_SEP.join(lookup_parts[0:n]) + if level_n_lookup in aggregates: + return aggregates[level_n_lookup], lookup_parts[n:] return False, () diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py index d971ea6380..e736c0332e 100644 --- a/django/db/models/lookups.py +++ b/django/db/models/lookups.py @@ -81,7 +81,7 @@ class Lookup(object): raise NotImplementedError -class DjangoLookup(Lookup): +class BuiltinLookup(Lookup): def as_sql(self, qn, connection): lhs_sql, params = self.process_lhs(qn, connection) field_internal_type = self.lhs.output_type.get_internal_type() @@ -100,47 +100,47 @@ class DjangoLookup(Lookup): default_lookups = {} -class Exact(DjangoLookup): +class Exact(BuiltinLookup): lookup_name = 'exact' default_lookups['exact'] = Exact -class IExact(DjangoLookup): +class IExact(BuiltinLookup): lookup_name = 'iexact' default_lookups['iexact'] = IExact -class Contains(DjangoLookup): +class Contains(BuiltinLookup): lookup_name = 'contains' default_lookups['contains'] = Contains -class IContains(DjangoLookup): +class IContains(BuiltinLookup): lookup_name = 'icontains' default_lookups['icontains'] = IContains -class GreaterThan(DjangoLookup): +class GreaterThan(BuiltinLookup): lookup_name = 'gt' default_lookups['gt'] = GreaterThan -class GreaterThanOrEqual(DjangoLookup): +class GreaterThanOrEqual(BuiltinLookup): lookup_name = 'gte' default_lookups['gte'] = GreaterThanOrEqual -class LessThan(DjangoLookup): +class LessThan(BuiltinLookup): lookup_name = 'lt' default_lookups['lt'] = LessThan -class LessThanOrEqual(DjangoLookup): +class LessThanOrEqual(BuiltinLookup): lookup_name = 'lte' default_lookups['lte'] = LessThanOrEqual -class In(DjangoLookup): +class In(BuiltinLookup): lookup_name = 'in' def get_db_prep_lookup(self, value, connection): @@ -158,27 +158,27 @@ class In(DjangoLookup): default_lookups['in'] = In -class StartsWith(DjangoLookup): +class StartsWith(BuiltinLookup): lookup_name = 'startswith' default_lookups['startswith'] = StartsWith -class IStartsWith(DjangoLookup): +class IStartsWith(BuiltinLookup): lookup_name = 'istartswith' default_lookups['istartswith'] = IStartsWith -class EndsWith(DjangoLookup): +class EndsWith(BuiltinLookup): lookup_name = 'endswith' default_lookups['endswith'] = EndsWith -class IEndsWith(DjangoLookup): +class IEndsWith(BuiltinLookup): lookup_name = 'iendswith' default_lookups['iendswith'] = IEndsWith -class Between(DjangoLookup): +class Between(BuiltinLookup): def get_rhs_op(self, connection, rhs): return "BETWEEN %s AND %s" % (rhs, rhs) @@ -193,7 +193,7 @@ class Range(Between): default_lookups['range'] = Range -class DateLookup(DjangoLookup): +class DateLookup(BuiltinLookup): def process_lhs(self, qn, connection): lhs, params = super(DateLookup, self).process_lhs(qn, connection) @@ -241,7 +241,7 @@ class Second(DateLookup): default_lookups['second'] = Second -class IsNull(DjangoLookup): +class IsNull(BuiltinLookup): lookup_name = 'isnull' def as_sql(self, qn, connection): @@ -253,16 +253,16 @@ class IsNull(DjangoLookup): default_lookups['isnull'] = IsNull -class Search(DjangoLookup): +class Search(BuiltinLookup): lookup_name = 'search' default_lookups['search'] = Search -class Regex(DjangoLookup): +class Regex(BuiltinLookup): lookup_name = 'regex' default_lookups['regex'] = Regex -class IRegex(DjangoLookup): +class IRegex(BuiltinLookup): lookup_name = 'iregex' default_lookups['iregex'] = IRegex