Skip to content

Commit

Permalink
Resolves #756.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Mar 27, 2024
1 parent d5406df commit 1cf0717
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 5 additions & 2 deletions workbench
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ def create():
node_uri,
)
if "output_csv" in config.keys():
write_to_output_csv(config, id_field, node_response.text, row)
# We pass a copy of the row into this function because Python.
write_to_output_csv(config, id_field, node_response.text, copy.deepcopy(row))
else:
message = "Node for CSV record " + id_field + " not created"
print("ERROR: " + message + ".")
Expand Down Expand Up @@ -495,7 +496,6 @@ def create():
row["file"],
media_response_status_code,
)

if config["nodes_only"] is False and "additional_files" in config:
additional_files_config = get_additional_files_config(config)
if len(additional_files_config) > 0:
Expand All @@ -504,6 +504,9 @@ def create():
additional_file_media_use_tid,
) in additional_files_config.items():
# If there is no additional media file, move on to the next "additional_files" column.
if additional_file_field not in row:
continue

if (
additional_file_field in row
and len(row[additional_file_field].strip()) == 0
Expand Down
20 changes: 19 additions & 1 deletion workbench_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7844,6 +7844,22 @@ def validate_taxonomy_reference_value(

def write_to_output_csv(config, id, node_json, input_csv_row=None):
"""Appends a row to the CVS file located at config['output_csv']."""
"""Parameters
----------
config : dict
The configuration settings defined by workbench_config.get_config().
id : str
The value of the CSV row's ID field.
node_json : str
The JSON representation of the node just created, provided by Drupal.
input_csv_row : dict
The CSV Reader representation of the current input CSV row. Note that
this is copy.deepcopy() of the CSV row since passing the row in as is
modifies it in global scope.
Returns
-------
None
"""
# Importing the workbench_fields module at the top of this module with the
# rest of the imports causes a circular import exception, so we do it here.
import workbench_fields
Expand Down Expand Up @@ -7876,10 +7892,12 @@ def write_to_output_csv(config, id, node_json, input_csv_row=None):
]
for field_to_remove in fields_to_remove:
if field_to_remove in node_field_names:
# print("DEBUG", field_to_remove)
node_field_names.remove(field_to_remove)

reserved_fields = ["file", "parent_id", "url_alias", "image_alt_text", "checksum"]
additional_files_columns = list(get_additional_files_config(config).keys())
if len(additional_files_columns) > 0:
reserved_fields = reserved_fields + additional_files_columns

csvfile = open(config["output_csv"], "a+", encoding="utf-8")

Expand Down

0 comments on commit 1cf0717

Please sign in to comment.