Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Limit & Sort with Filter #97

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions lizmap_server/expression_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,30 +868,6 @@ def virtualFields(params: Dict[str, str], response: QgsServerResponse, project:

req = QgsFeatureRequest()

# set limit
req_limit = params.get('LIMIT', '-1')
try:
req.setLimit(int(req_limit))
except ValueError:
raise ExpressionServiceError(
"Bad request error",
f"Invalid LIMIT for 'VirtualFields': \"{req_limit}\"",
400)

# set orderby
req_sorting_order_param = params.get('SORTING_ORDER', '')

if req_sorting_order_param in ('asc', 'desc'):
# QGIS expects a boolean to know how to sort
req_sorting_field = params.get('SORTING_FIELD', '')
order_by_clause = QgsFeatureRequest.OrderByClause(req_sorting_field, req_sorting_order_param == 'asc')
req.setOrderBy(QgsFeatureRequest.OrderBy([order_by_clause]))
elif req_sorting_order_param != '' :
raise ExpressionServiceError(
"Bad request error",
f"Invalid SORTING_ORDER for 'VirtualFields': \"{req_sorting_order_param}\"",
400)

# get filter
req_filter = params.get('FILTER', '')
if req_filter:
Expand All @@ -916,6 +892,30 @@ def virtualFields(params: Dict[str, str], response: QgsServerResponse, project:
req_exp.prepare(exp_context)
req = QgsFeatureRequest(req_exp, exp_context)

# set limit
req_limit = params.get('LIMIT', '-1')
try:
req.setLimit(int(req_limit))
except ValueError:
raise ExpressionServiceError(
"Bad request error",
f"Invalid LIMIT for 'VirtualFields': \"{req_limit}\"",
400)

# set orderby
req_sorting_order_param = params.get('SORTING_ORDER', '')

if req_sorting_order_param in ('asc', 'desc'):
# QGIS expects a boolean to know how to sort
req_sorting_field = params.get('SORTING_FIELD', '')
order_by_clause = QgsFeatureRequest.OrderByClause(req_sorting_field, req_sorting_order_param == 'asc')
req.setOrderBy(QgsFeatureRequest.OrderBy([order_by_clause]))
elif req_sorting_order_param != '' :
raise ExpressionServiceError(
"Bad request error",
f"Invalid SORTING_ORDER for 'VirtualFields': \"{req_sorting_order_param}\"",
400)

# With geometry
with_geom = to_bool(params.get('WITH_GEOMETRY'))
if not with_geom:
Expand Down