Skip to content

Commit

Permalink
Add property vectorjoin_id to REST API /vector/api/config/.
Browse files Browse the repository at this point in the history
  • Loading branch information
wlorenzetti committed Sep 18, 2023
1 parent ff1c801 commit c2cfd9b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions g3w-admin/core/utils/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@


def editingFormField(fieldName, type=FIELD_TYPE_STRING, editable=True, required=False, validate=None,
fieldLabel=None, inputType=None, values=None, default_clause='', unique=False, expression='', pk=False, ** kwargs):
fieldLabel=None, inputType=None, values=None, default_clause='', unique=False, expression='',
pk=False, ** kwargs):
"""
Build editing form field for client.
"""
Expand Down Expand Up @@ -222,6 +223,13 @@ def mapLayerAttributesFromQgisLayer(qgis_layer, **kwargs):

pk_attributes = qgis_layer.primaryKeyAttributes()

# Get available Join's fields
join_fields = {}
for order, join in enumerate(qgis_layer.vectorJoins()):
join_id = f'{qgis_layer.id()}_vectorjoin_{order}'
for f in join.joinLayer().fields():
join_fields[join.prefixedFieldName(f)] = join_id

# Determine if we are using an old and bugged version of QGIS
IS_QGIS_3_10 = Qgis.QGIS_VERSION.startswith('3.10')

Expand Down Expand Up @@ -282,8 +290,6 @@ def mapLayerAttributesFromQgisLayer(qgis_layer, **kwargs):
else:
is_pk = (field_index in pk_attributes)

#

toRes[field.name()] = editingFormField(
field.name(),
required=not_null,
Expand Down Expand Up @@ -342,6 +348,12 @@ def mapLayerAttributesFromQgisLayer(qgis_layer, **kwargs):
toRes[field.name()]['input']['options']['default_expression']['apply_on_update'] = True \
if field.defaultValueDefinition().applyOnUpdate() else False

# Check for Join's field
try:
toRes[field.name()]['vectorjoin_id'] = join_fields[field.name()]
except:
pass

field_index += 1

return toRes
Expand Down

0 comments on commit c2cfd9b

Please sign in to comment.