分离search_fields(搜索表单字段定义)和data_filter(逻辑表达式)
This commit is contained in:
parent
db5f579464
commit
b4ac434b62
@ -73,8 +73,8 @@ data_browser_tmpl = """
|
||||
{% if content_view %}
|
||||
"content_view":{{json.dumps(content_view, indent=4, ensure_ascii=False)}},
|
||||
{% endif %}
|
||||
{% if data_filter %}
|
||||
"data_filter":{{json.dumps(data_filter, indent=4, ensure_ascii=False)}},
|
||||
{% if search_fields %}
|
||||
"search_fields":{{json.dumps(search_fields, indent=4, ensure_ascii=False)}},
|
||||
"search_form":{
|
||||
"css":"card",
|
||||
"padding":"8px",
|
||||
@ -159,28 +159,24 @@ sql = '''{{sql}}'''
|
||||
{% if not relation %}
|
||||
filterjson = params_kw.get('data_filter')
|
||||
if filterjson and isinstance(filterjson, str):
|
||||
\ttry:
|
||||
\t\tfilterjson = json.loads(filterjson)
|
||||
\texcept (json.JSONDecodeError, TypeError):
|
||||
\t\tfilterjson = None
|
||||
# data_filter可能是CRUD字段定义({"fields":[...]}),不是过滤条件,忽略
|
||||
if filterjson and isinstance(filterjson, dict) and 'fields' in filterjson:
|
||||
filterjson = None
|
||||
try:
|
||||
filterjson = json.loads(filterjson)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
filterjson = None
|
||||
fields_str=r'''{{json.dumps(fields, indent=4, ensure_ascii=False)}}'''
|
||||
ori_fields = json.loads(fields_str)
|
||||
if not filterjson:
|
||||
fields = [ f['name'] for f in ori_fields ]
|
||||
filterjson = default_filterjson(fields, ns)
|
||||
{% if data_filter and data_filter.fields %}
|
||||
# 应用 data_filter 中显式声明的 op(如 LIKE)
|
||||
__df_fields = {{json.dumps(data_filter.fields, ensure_ascii=False)}}
|
||||
__df_ops = {f['field']: f.get('op') for f in __df_fields if f.get('op')}
|
||||
if filterjson and __df_ops:
|
||||
{% if search_fields %}
|
||||
# 应用 search_fields 中显式声明的 op(如 LIKE)
|
||||
__sf_ops = {f['field']: f.get('op') for f in {{json.dumps(search_fields, ensure_ascii=False)}} if f.get('op')}
|
||||
if filterjson and __sf_ops:
|
||||
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
|
||||
filterjson = {'AND': [filterjson] if filterjson else []}
|
||||
for fj in filterjson['AND']:
|
||||
if fj.get('field') in __df_ops:
|
||||
fj['op'] = __df_ops[fj['field']]
|
||||
if fj.get('field') in __sf_ops:
|
||||
fj['op'] = __sf_ops[fj['field']]
|
||||
if fj['op'] == 'LIKE':
|
||||
var = fj.get('var')
|
||||
if var and var in ns and ns[var]:
|
||||
|
||||
@ -257,9 +257,9 @@ def filter_backslash(s):
|
||||
|
||||
def build_filter_field_list(desc) -> list:
|
||||
"""Build enriched filter field list for InlineForm search form.
|
||||
When a data_filter field has uitype='code', auto-populate
|
||||
When a search_fields field has uitype='code', auto-populate
|
||||
valueField/textField/params/dataurl from the model's codes definition."""
|
||||
if not desc.data_filter or not desc.data_filter.get('fields'):
|
||||
if not desc.search_fields:
|
||||
return []
|
||||
codes_map = {}
|
||||
if desc.codes:
|
||||
@ -269,7 +269,7 @@ def build_filter_field_list(desc) -> list:
|
||||
codes_map[cfield] = c
|
||||
modulename = getattr(desc, 'modulename', '')
|
||||
result = []
|
||||
for f in desc.data_filter.fields:
|
||||
for f in desc.search_fields:
|
||||
field_name = f.field if isinstance(f, dict) else getattr(f, 'field', '')
|
||||
field_title = f.title if isinstance(f, dict) else getattr(f, 'title', '')
|
||||
field_uitype = f.uitype if isinstance(f, dict) else getattr(f, 'uitype', 'str')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user