Skip to content

Commit

Permalink
'suggest' parameter in combination with 'fformatter' parameter (#811)
Browse files Browse the repository at this point in the history
* Refactoring

* Apply pythonic 'suggest' 'ilike' expression to formatted end values.

* Desc

* Add fformatter and suggest checks.

* Remove `AutoCompleteBox` widget type for `ValueRelation`

---------

Co-authored-by: wlorenzetti <[email protected]>
  • Loading branch information
wlorenzetti and wlorenzetti authored Apr 15, 2024
1 parent a3b5636 commit 48c0440
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
19 changes: 17 additions & 2 deletions g3w-admin/core/api/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,27 @@ def response_data_mode(self, request, export_features=False):
QVariant(),
u
)
values.append([json.loads(QgsJsonUtils.encodeValue(u)), fvalue])

to_append = True

# 'suggest' (get/post) parameter used inside the QGIS SuggestFilterBackend
# must be applied to the formatted value (fvalue) because the result of formatted value
# can also derive from QgsExression(s).
if 'suggest' in self.request_data and 'fformatter' in self.request_data:

# Replace suggest file with r_pvalue if pvalue == suggest field
s_field, s_value = self.request_data.get('suggest').split('|')
to_append = False
if s_field == pvalue and str(s_value).lower() in str(fvalue).lower():
to_append = True

if to_append:
values.append([json.loads(QgsJsonUtils.encodeValue(u)), fvalue])
except Exception as e:
logger.error(f'Response vector widget unique: {e}')
continue

# sort values
# Sort values
if ('fformatter' in self.request_data
and 'ordering' in self.request_data
and self.request_data['fformatter'] in self.request_data['ordering']):
Expand Down
6 changes: 1 addition & 5 deletions g3w-admin/core/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,7 @@ def apply_filter(self, request, metadata_layer, qgis_feature_request, view):
qgis_layer = metadata_layer.qgis_layer

# Try to get param from GET
suggest_value = request.query_params.get('suggest')

if not suggest_value:
# Try to get from POST
suggest_value = request.data.get('suggest')
suggest_value = request.query_params.get('suggest', request.data.get('suggest'))

if suggest_value:

Expand Down
9 changes: 8 additions & 1 deletion g3w-admin/qdjango/static/qdjango/js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ ga.Qdjango.widgetEditor = {

var widgetSelect = $('<select class="form-control" name="widget_type"></select>')
$.each(options, function (k, i) {
widgetSelect.append('<option value="' + k + '">' + i + "</option>")
widgetSelect.append('<option value="' + k + '">' + i + "</option>")
})

// add widget types
Expand Down Expand Up @@ -412,6 +412,13 @@ ga.Qdjango.widgetEditor = {
widgetSelect.append('<option value="datetimebox">' + that.datetime_widgettype.datetimebox + '</option>');
}

// Remove `AutoCompleteBox` from widget type list
if (ga.Qdjango.localVars.layer_edittypes[$(this).val()].widgetv2type == 'ValueRelation') {
widgetSelect.find("option[value=\"autocompletebox\"]").hide();
} else {
widgetSelect.find("option[value=\"autocompletebox\"]").show();
}

})

// Trigger change for fieldselect
Expand Down

0 comments on commit 48c0440

Please sign in to comment.