Skip to content

Commit

Permalink
Added missing file.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed May 4, 2020
1 parent 3aed212 commit 30657d3
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions modules/field_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from workbench_utils import *


def update(config, field_definition, csv_row_value, node_field_values, custom_field, node_id):
if field_definition['cardinality'] == 1:
subvalues = csv_row_value.split(config['subdelimiter'])
node_field_value = [{'value': subvalues[0]}]
if len(subvalues) > 1:
log_field_cardinality_violation(custom_field, node_id, '1')
elif field_definition['cardinality'] > 1:
# Append to existing values.
if config['subdelimiter'] in csv_row_value:
field_values = []
subvalues = csv_row_value.split(config['subdelimiter'])
if len(subvalues) > field_definition['cardinality']:
log_field_cardinality_violation(custom_field, node_id, field_definition['cardinality'])
subvalues = subvalues[:field_definition['cardinality']]
for subvalue in subvalues:
field_values.append({'value': subvalue})
if config['update_mode'] == 'append':
custom_field = node_field_values[custom_field] + field_values
else:
custom_field = field_values
else:
if config['update_mode'] == 'append':
custom_field = node_field_values[custom_field] + [{'value': csv_row_value}]
else:
custom_field = [{'value': csv_row_value}]
# Cardinatlity is unlimited.
else:
# Append to existing values.
if config['subdelimiter'] in csv_row_value:
field_values = []
subvalues = csv_row_value.split(config['subdelimiter'])
for subvalue in subvalues:
field_values.append({'value': subvalue})
if config['update_mode'] == 'append':
custom_field = node_field_values[custom_field] + field_values
else:
custom_field = field_values
else:
if config['update_mode'] == 'append':
custom_field = node_field_values[custom_field] + [{'value': csv_row_value}]
else:
custom_field = [{'value': csv_row_value}]

return custom_field

0 comments on commit 30657d3

Please sign in to comment.