5
5
from django .db import models , connection
6
6
from django .db .models import sql , query
7
7
8
- NET_TERMS = {
8
+ NET_OPERATORS = {
9
9
'lt' : '%s < %s' ,
10
10
'lte' : '%s <= %s' ,
11
11
'exact' : '%s = %s' ,
22
22
'regex' : '%s ~* %s' ,
23
23
}
24
24
25
- NET_TERMS_TEXT_LOOKUPS = set ([
25
+ NET_TEXT_LOOKUPS = set ([
26
26
'contains' ,
27
27
'startswith' ,
28
28
'endswith' ,
29
29
'regex' ,
30
30
])
31
31
32
- NET_TERMS_MAPPING = {
32
+ NET_MAPPING = {
33
33
'iexact' : 'exact' ,
34
34
'icontains' : 'contains' ,
35
35
'istartswith' : 'startswith' ,
41
41
42
42
class NetQuery (sql .Query ):
43
43
query_terms = sql .Query .query_terms .copy ()
44
- query_terms .update (NET_TERMS )
44
+ query_terms .update (NET_OPERATORS )
45
45
46
46
def add_filter (self , (filter_string , value ), * args , ** kwargs ):
47
47
# IP(...) == '' fails so make sure to force to string while we can
@@ -64,19 +64,19 @@ def make_atom(self, child, qn):
64
64
if lookup_type == 'regex' :
65
65
lhs = 'HOST(%s)' % field_sql
66
66
rhs = '%s'
67
- elif lookup_type in NET_TERMS_TEXT_LOOKUPS :
67
+ elif lookup_type in NET_TEXT_LOOKUPS :
68
68
lhs = 'UPPER(HOST(%s))' % field_sql
69
69
rhs = 'UPPER(%s)'
70
70
else :
71
71
lhs = field_sql
72
72
rhs = '%s'
73
73
74
- if lookup_type in NET_TERMS_MAPPING :
75
- lookup_type = NET_TERMS_MAPPING [lookup_type ]
74
+ if lookup_type in NET_MAPPING :
75
+ lookup_type = NET_MAPPING [lookup_type ]
76
76
child = (table_alias , name , db_type , lookup_type , value_annot , params )
77
77
return self .make_atom (child , qn )
78
- elif lookup_type in NET_TERMS :
79
- return (NET_TERMS [lookup_type ] % (lhs , rhs ), params )
78
+ elif lookup_type in NET_OPERATORS :
79
+ return (NET_OPERATORS [lookup_type ] % (lhs , rhs ), params )
80
80
elif lookup_type == 'in' :
81
81
return ('%s IN (%s)' % (lhs , ', ' .join ([rhs ] * len (params ))), params )
82
82
elif lookup_type == 'range' :
@@ -121,11 +121,11 @@ def get_db_prep_lookup(self, lookup_type, value):
121
121
if value is None :
122
122
return value
123
123
124
- if lookup_type in NET_TERMS_MAPPING :
124
+ if lookup_type in NET_MAPPING :
125
125
return self .get_db_prep_lookup (
126
- NET_TERMS_MAPPING [lookup_type ], value )
126
+ NET_MAPPING [lookup_type ], value )
127
127
128
- if lookup_type in NET_TERMS and lookup_type not in NET_TERMS_TEXT_LOOKUPS :
128
+ if lookup_type in NET_OPERATORS and lookup_type not in NET_TEXT_LOOKUPS :
129
129
return [self .get_db_prep_value (value )]
130
130
131
131
return super (_NetAddressField , self ).get_db_prep_lookup (
0 commit comments