From fe5d2561681f6e360a9e2c122bad4df7a4770b03 Mon Sep 17 00:00:00 2001 From: ajstanley Date: Sun, 27 Oct 2024 20:49:33 -0300 Subject: [PATCH] added override to assign media types by media use --- WorkbenchConfig.py | 1 + i7Import/i7ImportUtilities.py | 7 +++++++ workbench_utils.py | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/WorkbenchConfig.py b/WorkbenchConfig.py index 4781727..3ab00b5 100644 --- a/WorkbenchConfig.py +++ b/WorkbenchConfig.py @@ -286,6 +286,7 @@ def get_default_config(self): "csv_value_templates_rand_length": 5, "allow_csv_value_templates_if_field_empty": [], "remind_user_to_run_check": False, + "media_type_by_media_use": False, } # Tests validity and existence of configuration file path. diff --git a/i7Import/i7ImportUtilities.py b/i7Import/i7ImportUtilities.py index e60b45e..4cc9078 100644 --- a/i7Import/i7ImportUtilities.py +++ b/i7Import/i7ImportUtilities.py @@ -56,6 +56,7 @@ def __init__(self, config_location): "start": 0, "rows": 100000, "secure_ssl_only": True, + "pids": False, } def get_config(self): @@ -181,6 +182,12 @@ def get_default_metadata_solr_request(self): fedora_collections.append(f'{fedora_prefix}"{collection}"') fq_string = "&fq=" + " or ".join(fedora_collections) query = f"{query}{fq_string}" + if self.config["pids"]: + pids_to_use = [] + for candidate in self.config["pids"]: + pids_to_use.append(f"PID:{candidate}") + fq_string = "&fq=" + " or ".join(pids_to_use) + query = f"{query}{fq_string}" # Get the populated CSV from Solr, with the object namespace and field list filters applied. return query diff --git a/workbench_utils.py b/workbench_utils.py index 534fc01..d0ee378 100644 --- a/workbench_utils.py +++ b/workbench_utils.py @@ -79,6 +79,14 @@ def set_media_type(config, filepath, file_fieldname, csv_row): """ if "media_type" in config: return config["media_type"] + if config["media_type_by_media_use"] and len(config["media_type_by_media_use"]) > 0: + additional_files = get_additional_files_config(config) + media_url = additional_files.get(file_fieldname) + if file_fieldname in additional_files: + for entry in config["media_type_by_media_use"]: + for key, value in entry.items(): + if key == media_url: + return value # Determine if the incomtimg filepath matches a registered eEmbed media type. oembed_media_type = get_oembed_url_media_type(config, filepath)