Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions multilingual_tests/create_content.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
file,id,title,field_subject,field_model
,01,Ancient Architecture,Architecture,Collection
,02,Photography Collection,Photography,Collection
,03,Literary Manuscripts,Literature,Collection
11 changes: 11 additions & 0 deletions multilingual_tests/create_content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
task: create
host: https://islandora.dev
username: admin
password: password
input_csv: multilingual_tests/create_content.csv
input_dir: ""
content_type: islandora_object
media_type: image
allow_missing_files: true
allow_adding_terms: true
secure_ssl_only: false
4 changes: 4 additions & 0 deletions multilingual_tests/create_taxonomy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
term_name
"History"
"Photography"
"Architecture"
9 changes: 9 additions & 0 deletions multilingual_tests/create_taxonomy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
task: create_terms
host: https://islandora.dev
username: admin
password: password
input_csv: multilingual_tests/create_taxonomy.csv
input_dir: ""
vocabulary: subject
vocab_id: subject
secure_ssl_only: false
7 changes: 7 additions & 0 deletions multilingual_tests/translate_content.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_id,title,field_subject,langcode
109,古代建筑,Architecture,zh-hant
109,Architettura Antica,Architecture,it
110,摄影收藏,Photography,zh-hant
110,Collezione Fotografica,Photography,it
111,文学手稿,Literature,zh-hant
111,Manoscritti Letterari,Literature,it
10 changes: 10 additions & 0 deletions multilingual_tests/translate_content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
task: update
host: https://islandora.dev
username: admin
password: password
input_csv: multilingual_tests/translate_content.csv
input_dir: ""
content_type: islandora_object
media_type: image
allow_missing_files: true
secure_ssl_only: false
7 changes: 7 additions & 0 deletions multilingual_tests/translate_terms.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
term_id,term_name,description,langcode
960,历史,中文历史描述,zh-hant
960,Storia,Descrizione italiana per Storia,it
958,摄影,中文摄影描述,zh-hant
958,Fotografia,Descrizione italiana per Fotografia,it
957,建筑学,中文建筑学描述,zh-hant
957,Architettura,Descrizione italiana per Architettura,it
11 changes: 11 additions & 0 deletions multilingual_tests/translate_terms.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
task: update_terms
host: https://islandora.dev
username: admin
password: password
input_csv: multilingual_tests/translate_terms.csv
input_dir: ""
vocabulary: subject
vocab_id: subject
secure_ssl_only: false
log_request_url: true
log_response_status_code: true
26 changes: 20 additions & 6 deletions workbench
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,11 @@ def update():
if node_has_all_fields is True:
if value_is_numeric(row["node_id"]) is False:
row["node_id"] = get_nid_from_url_alias(config, row["node_id"])
node_endpoint = (
config["host"] + "/node/" + str(row["node_id"]) + "?_format=json"
)

# Build language-specific endpoint if langcode is specified
langcode = row.get("langcode", "").strip() if "langcode" in row else None
language_prefix = f"/{langcode}" if langcode else ""
node_endpoint = f"{config['host']}{language_prefix}/node/{row['node_id']}?_format=json"
node_headers = {"Content-Type": "application/json"}
# Make a GET request to the content type
content_type_endpoint = f"{config['host']}/entity/node_type/{config['content_type']}?_format=json"
Expand Down Expand Up @@ -912,6 +914,8 @@ def update():
create_url_alias(config, row["node_id"], row["url_alias"])




def delete():
"""Delete nodes."""
message = '"Delete" task started using config file ' + args.config + "."
Expand Down Expand Up @@ -2873,6 +2877,10 @@ def update_terms():
if len(row["published"].strip()) != 0:
term["status"] = [{"value": row["published"]}]

if "langcode" in csv_column_headers:
if len(row["langcode"]) > 0:
term["langcode"] = [{"value": row["langcode"]}]

# Add custom (non-required) fields.
required_fields = ["term_id"]
custom_fields = list(set(csv_column_headers) - set(required_fields))
Expand All @@ -2885,6 +2893,7 @@ def update_terms():
"description",
"term_name",
"published",
"langcode",
]
if (
custom_field not in json.loads(term_response.text)
Expand Down Expand Up @@ -2916,6 +2925,10 @@ def update_terms():
if custom_field == "published":
continue

# 'langcode' is a core Drupal field, but is not considered a base field.
if custom_field == "langcode":
continue

# Assemble Drupal field structures from CSV data. If new field types are added to
# workbench_fields.py, they need to be registered in the following if/elif/else block.

Expand All @@ -2932,9 +2945,10 @@ def update_terms():
)

if term_has_all_fields is True:
term_endpoint = (
config["host"] + "/taxonomy/term/" + row["term_id"] + "?_format=json"
)
# Build language-specific endpoint if langcode is specified
langcode = row.get("langcode", "").strip() if "langcode" in row else None
language_prefix = f"/{langcode}" if langcode else ""
term_endpoint = f"{config['host']}{language_prefix}/taxonomy/term/{row['term_id']}?_format=json"
term_headers = {"Content-Type": "application/json"}
term_response = issue_request(
config, "PATCH", term_endpoint, term_headers, term
Expand Down
9 changes: 8 additions & 1 deletion workbench_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
commented_out_input_csv_rows_present = False




def set_media_type(config, filepath, file_fieldname, csv_row):
"""Using either the 'media_type' or 'media_types_override' configuration
setting, determine which media bundle type to use.
Expand Down Expand Up @@ -6635,7 +6637,12 @@ def get_csv_data(config, csv_file_target="node_fields", file_path=None):
row["node_id"] = get_nid_from_url_alias(config, row["node_id"])

try:
unique_identifiers.append(row[config["id_field"]])
# If langcode is present, create composite key to allow same entity ID with different langcodes
if "langcode" in row and row["langcode"].strip():
identifier_key = f"{row[config['id_field']]}|{row['langcode']}"
else:
identifier_key = row[config["id_field"]]
unique_identifiers.append(identifier_key)

if (
"csv_value_templates" in config
Expand Down