Skip to content

Commit

Permalink
Warn user about field in a join or virtual in the form filter tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Oct 27, 2023
1 parent 2febb21 commit bf95b0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions lizmap/forms/base_edition_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def accept(self):
if message:
self.error.setVisible(True)
self.error.setText(message)
self.error.setWordWrap(True)
else:
super().accept()

Expand Down
24 changes: 23 additions & 1 deletion lizmap/forms/filter_by_form_edition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dialog for filter by form."""

from qgis.core import QgsMapLayerProxyModel, QgsProject
from qgis.core import QgsFields, QgsMapLayerProxyModel, QgsProject
from qgis.PyQt.QtGui import QIcon

from lizmap import LwcVersions
Expand Down Expand Up @@ -203,3 +203,25 @@ def validate(self) -> str:
return field_required
else:
raise Exception('Unknown option')

# Check for join, or virtual fields
field_origin = tr(
'The field "{}" is not provided by the underlying table. It can not come from a join or be a virtual '
'field. This tool is using plain SQL query on the underlying table.')
forbidden = (QgsFields.FieldOrigin.OriginJoin, QgsFields.FieldOrigin.OriginExpression)
widget_fields = (
self.field,
self.start_field,
self.end_field,
)
for widget in widget_fields:
if not widget.isVisible():
# Deeper bug, do we save this value ?
continue

if not widget.currentField():
continue

index = self.layer.currentLayer().fields().indexFromName(widget.currentField())
if self.layer.currentLayer().fields().fieldOrigin(index) in forbidden:
return field_origin.format(widget.currentField())

0 comments on commit bf95b0c

Please sign in to comment.