Skip to content

Commit

Permalink
Improve selectComponent to support the Data Source Type: URL
Browse files Browse the repository at this point in the history
Improve the selectComponent class to support the property Data
Source Type (dataSrc) with URL.
This applies to the methods value_label and value_labels, which
use the stored label(s).
So this doesn't execute a request to the URL, because we can't take
any control (e.g. due to authentication) over the host/server/service,
  • Loading branch information
bobslee committed May 23, 2024
1 parent a2a639e commit a5ea234
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.0.2

Improve the `selectComponent` class to support the property Data Source Type (`dataSrc`) with URL.\
This applies to the methods `value_label` and `value_labels`, which use the stored label(s).\
So this doesn't execute a request to the URL, because we can't take any control (e.g. due to authentication) over the host/server/service,

## 2.0.1

Improve the `Component` class `conditional_visible_when` method, to also obtain a Dictionary for the value of triggering component.\
Expand Down
68 changes: 44 additions & 24 deletions formiodata/components/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,65 @@

class selectComponent(Component):

@property
def dataSrc(self):
return self.raw.get('dataSrc')

@property
def multiple(self):
return self.raw.get('multiple')

@property
def value_label(self):
comp = self.component_owner.input_components.get(self.key)
data_type = comp.raw.get('dataType')
values = comp.raw.get('data') and comp.raw['data'].get('values')
for val in values:
if data_type == 'number':
data_val = int(val['value'])
if self.dataSrc == 'url':
label = self.value['label']
if self.i18n.get(self.language):
return self.i18n[self.language].get(label, label)
else:
data_val = val['value']

if data_val == self.value:
label = val['label']
if self.i18n.get(self.language):
return self.i18n[self.language].get(label, label)
else:
return label
return label
else:
return False
data_type = comp.raw.get('dataType')
values = comp.raw.get('data') and comp.raw['data'].get('values')
for val in values:
if data_type == 'number':
data_val = int(val['value'])
else:
data_val = val['value']

if data_val == self.value:
label = val['label']
if self.i18n.get(self.language):
return self.i18n[self.language].get(label, label)
else:
return label
else:
return False

@property
def value_labels(self):
comp = self.component_owner.input_components.get(self.key)
data_type = comp.raw.get('dataType')
values = comp.raw.get('data') and comp.raw['data'].get('values')
value_labels = []
for val in values:
if data_type == 'number':
data_val = int(val['value'])
else:
data_val = val['value']

if self.value and data_val in self.value:
if self.dataSrc == 'url':
for val in self.value:
label = val['label']
if self.i18n.get(self.language):
value_labels.append(self.i18n[self.language].get(val['label'], val['label']))
label = self.i18n[self.language].get(label, label)
value_labels.append(label)
else:
data_type = comp.raw.get('dataType')
values = comp.raw.get('data') and comp.raw['data'].get('values')

for val in values:
if data_type == 'number':
data_val = int(val['value'])
else:
value_labels.append(val['label'])
data_val = val['value']

if self.value and data_val in self.value:
if self.i18n.get(self.language):
value_labels.append(self.i18n[self.language].get(val['label'], val['label']))
else:
value_labels.append(val['label'])
return value_labels
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "formio-data"
version = "2.0.1"
version = "2.0.2"
homepage = "https://github.com/novacode-nl/python-formio-data"
description = "formio.js JSON-data API"
readme = "README.md"
Expand Down

0 comments on commit a5ea234

Please sign in to comment.