Fixed #27736 -- Used decorators for lookup registration.

This commit is contained in:
Mads Jensen 2017-01-16 15:22:26 +01:00 committed by Tim Graham
parent 05bdf4f44d
commit 0bc59978ab
1 changed files with 20 additions and 60 deletions

View File

@ -235,13 +235,12 @@ class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin):
return sql, tuple(params)
@Field.register_lookup
class Exact(FieldGetDbPrepValueMixin, BuiltinLookup):
lookup_name = 'exact'
Field.register_lookup(Exact)
@Field.register_lookup
class IExact(BuiltinLookup):
lookup_name = 'iexact'
prepare_rhs = False
@ -253,37 +252,26 @@ class IExact(BuiltinLookup):
return rhs, params
Field.register_lookup(IExact)
@Field.register_lookup
class GreaterThan(FieldGetDbPrepValueMixin, BuiltinLookup):
lookup_name = 'gt'
Field.register_lookup(GreaterThan)
@Field.register_lookup
class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup):
lookup_name = 'gte'
Field.register_lookup(GreaterThanOrEqual)
@Field.register_lookup
class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup):
lookup_name = 'lt'
Field.register_lookup(LessThan)
@Field.register_lookup
class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup):
lookup_name = 'lte'
Field.register_lookup(LessThanOrEqual)
class IntegerFieldFloatRounding(object):
"""
Allow floats to work as query values for IntegerField. Without this, the
@ -295,20 +283,16 @@ class IntegerFieldFloatRounding(object):
return super(IntegerFieldFloatRounding, self).get_prep_lookup()
@IntegerField.register_lookup
class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual):
pass
IntegerField.register_lookup(IntegerGreaterThanOrEqual)
@IntegerField.register_lookup
class IntegerLessThan(IntegerFieldFloatRounding, LessThan):
pass
IntegerField.register_lookup(IntegerLessThan)
class DecimalComparisonLookup(object):
def as_sqlite(self, compiler, connection):
lhs_sql, params = self.process_lhs(compiler, connection)
@ -343,6 +327,7 @@ class DecimalLessThanOrEqual(DecimalComparisonLookup, LessThanOrEqual):
pass
@Field.register_lookup
class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
lookup_name = 'in'
@ -403,9 +388,6 @@ class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
return ''.join(in_clause_elements), params
Field.register_lookup(In)
class PatternLookup(BuiltinLookup):
def get_rhs_op(self, connection, rhs):
@ -425,6 +407,7 @@ class PatternLookup(BuiltinLookup):
return super(PatternLookup, self).get_rhs_op(connection, rhs)
@Field.register_lookup
class Contains(PatternLookup):
lookup_name = 'contains'
prepare_rhs = False
@ -436,17 +419,13 @@ class Contains(PatternLookup):
return rhs, params
Field.register_lookup(Contains)
@Field.register_lookup
class IContains(Contains):
lookup_name = 'icontains'
prepare_rhs = False
Field.register_lookup(IContains)
@Field.register_lookup
class StartsWith(PatternLookup):
lookup_name = 'startswith'
prepare_rhs = False
@ -458,9 +437,7 @@ class StartsWith(PatternLookup):
return rhs, params
Field.register_lookup(StartsWith)
@Field.register_lookup
class IStartsWith(PatternLookup):
lookup_name = 'istartswith'
prepare_rhs = False
@ -472,9 +449,7 @@ class IStartsWith(PatternLookup):
return rhs, params
Field.register_lookup(IStartsWith)
@Field.register_lookup
class EndsWith(PatternLookup):
lookup_name = 'endswith'
prepare_rhs = False
@ -486,9 +461,7 @@ class EndsWith(PatternLookup):
return rhs, params
Field.register_lookup(EndsWith)
@Field.register_lookup
class IEndsWith(PatternLookup):
lookup_name = 'iendswith'
prepare_rhs = False
@ -500,9 +473,7 @@ class IEndsWith(PatternLookup):
return rhs, params
Field.register_lookup(IEndsWith)
@Field.register_lookup
class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
lookup_name = 'range'
@ -510,9 +481,7 @@ class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
return "BETWEEN %s AND %s" % (rhs[0], rhs[1])
Field.register_lookup(Range)
@Field.register_lookup
class IsNull(BuiltinLookup):
lookup_name = 'isnull'
prepare_rhs = False
@ -525,9 +494,7 @@ class IsNull(BuiltinLookup):
return "%s IS NOT NULL" % sql, params
Field.register_lookup(IsNull)
@Field.register_lookup
class Search(BuiltinLookup):
lookup_name = 'search'
prepare_rhs = False
@ -543,9 +510,7 @@ class Search(BuiltinLookup):
return sql_template, lhs_params + rhs_params
Field.register_lookup(Search)
@Field.register_lookup
class Regex(BuiltinLookup):
lookup_name = 'regex'
prepare_rhs = False
@ -560,16 +525,11 @@ class Regex(BuiltinLookup):
return sql_template % (lhs, rhs), lhs_params + rhs_params
Field.register_lookup(Regex)
@Field.register_lookup
class IRegex(Regex):
lookup_name = 'iregex'
Field.register_lookup(IRegex)
class YearLookup(Lookup):
def year_lookup_bounds(self, connection, year):
output_field = self.lhs.lhs.output_field