bugfix
This commit is contained in:
parent
8b0db960a4
commit
fae798e183
@ -34,6 +34,25 @@ except:
|
||||
import json
|
||||
|
||||
class DBFilter(object):
|
||||
operators = [
|
||||
"=",
|
||||
"!=",
|
||||
"IN",
|
||||
"NOT IN",
|
||||
">",
|
||||
">=",
|
||||
"<",
|
||||
"<=",
|
||||
"IS NULL",
|
||||
"IS NOT NULL",
|
||||
"LIKE",
|
||||
"NOT LIKE"
|
||||
]
|
||||
logic = [
|
||||
"AND",
|
||||
"OR",
|
||||
"NOT"
|
||||
]
|
||||
def __init__(self,filterjson):
|
||||
if isinstance(filterjson, str):
|
||||
filterjson = json.loads(filterjson)
|
||||
@ -103,9 +122,12 @@ class DBFilter(object):
|
||||
keys = fj.keys()
|
||||
assert 'field' in keys
|
||||
assert 'op' in keys
|
||||
assert 'const' in keys or 'var' in keys
|
||||
op = fj.get('op')
|
||||
assert op in ['=','<>','>','<','>=','<=','in','not in']
|
||||
assert 'const' in keys or 'var' in keys or fj['op'].upper() in ['IS NULL', 'IS NOT NULL']
|
||||
op = fj.get('op').upper()
|
||||
assert op in self.operators
|
||||
|
||||
if op in ['IS NULL', 'IS NOT NULL']:
|
||||
return f'{fj['field']} {op}'
|
||||
|
||||
var = fj.get('var')
|
||||
if var and not var in ns.keys():
|
||||
@ -128,6 +150,11 @@ def default_filterjson(fields: list, ns: dict):
|
||||
'op':'=',
|
||||
'var':k
|
||||
} for k in ns.keys() if k in fields ]
|
||||
print(f'default_filterjson():{c=}')
|
||||
if len(c) < 1:
|
||||
return None
|
||||
if len(c) < 2:
|
||||
return c[0]
|
||||
return {
|
||||
'AND':c
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user