check ordering exists

This commit is contained in:
Aaron Kable
2026-01-09 07:51:06 +08:00
parent a01598e088
commit 6c2cbb069f

View File

@@ -54,12 +54,28 @@ class DataTablesView(View):
for id, c in table_conf["columns"].items():
_c = self.columns[int(id)][0]
if c["searchable"] and len(_c) > 0:
_sv = str(c["search"]["value"])
if len(_sv) > 0:
if c["search"]["regex"]:
filter_qs |= Q(**{f'{_c}__iregex': _sv})
else:
filter_qs |= Q(**{f'{_c}__icontains': _sv})
if c["columnControl"]:
_sv = str(c["columnControl"]["search"]["value"])
_logic = str(c["columnControl"]["search"]["logic"])
_type = str(c["columnControl"]["search"]["type"])
if len(_sv) > 0:
if _logic == "contains":
filter_qs |= Q(**{f'{_c}__icontains': _sv})
elif _logic == "starts":
filter_qs |= Q(**{f'{_c}__istartswith': _sv})
elif _logic == "ends":
filter_qs |= Q(**{f'{_c}__iendswith': _sv})
elif _logic == "equal":
filter_qs |= Q(**{f'{_c}': _sv})
elif _logic == "empty":
filter_qs |= Q(**{f'{_c}': ""})
else:
_sv = str(c["search"]["value"])
if len(_sv) > 0:
if c["search"]["regex"]:
filter_qs |= Q(**{f'{_c}__iregex': _sv})
else:
filter_qs |= Q(**{f'{_c}__icontains': _sv})
_gsv = str(table_conf["search"]["value"])
if len(_gsv) > 0:
filter_qs |= Q(**{f'{_c}__icontains': _gsv})
@@ -82,7 +98,7 @@ class DataTablesView(View):
def get_order(self, table_conf: dict):
order = []
for oc, od in table_conf["order"].items():
for oc, od in table_conf.get("order", {}).items():
_c = table_conf["columns"][od["column"]]
if _c["orderable"]:
if od["dir"] == "desc":