From 2367ea6309a1d4be70f26e0684cdc6c1876892f4 Mon Sep 17 00:00:00 2001 From: Kevin Cloud Date: Wed, 5 Jul 2023 12:24:47 -0400 Subject: [PATCH 1/3] Provide helper to select location title from get_data response --- process_request/helpers.py | 12 ++++++++++-- request_broker/config.py.deploy | 1 + request_broker/config.py.example | 1 + request_broker/settings.py | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/process_request/helpers.py b/process_request/helpers.py index 19d982e..87d0177 100644 --- a/process_request/helpers.py +++ b/process_request/helpers.py @@ -69,10 +69,18 @@ def make_short_location(loc_data): if loc_data.get("building") in settings.OFFSITE_BUILDINGS: location_list.insert(0, loc_data["building"]) return ".".join(location_list) + + def use_full_location(loc_data): + location_list = loc_data.get("title", "").strip() + return location_list locations = None - if top_container_info.get("container_locations"): - locations = ",".join([make_short_location(c["_resolved"]) for c in top_container_info.get("container_locations")]) + if settings.USE_LOCATION_TITLE == True: + if top_container_info.get("container_locations"): + locations = ",".join([use_full_location(c["_resolved"]) for c in top_container_info.get("container_locations")]) + else: + if top_container_info.get("container_locations"): + locations = ",".join([make_short_location(c["_resolved"]) for c in top_container_info.get("container_locations")]) return locations diff --git a/request_broker/config.py.deploy b/request_broker/config.py.deploy index 721f33d..a1bfcbd 100644 --- a/request_broker/config.py.deploy +++ b/request_broker/config.py.deploy @@ -23,3 +23,4 @@ DIMES_BASEURL = "${DIMES_BASEURL}" RESTRICTED_IN_CONTAINER = ${RESTRICTED_IN_CONTAINER} OFFSITE_BUILDINGS = ${OFFSITE_BUILDINGS} RESOURCE_ID_SEPARATOR = "${RESOURCE_ID_SEPARATOR}" +USE_LOCATION_TITLE = ${USE_LOCATION_TITLE} diff --git a/request_broker/config.py.example b/request_broker/config.py.example index b201637..c1d72bc 100644 --- a/request_broker/config.py.example +++ b/request_broker/config.py.example @@ -23,3 +23,4 @@ DIMES_BASEURL = "https://dimes.rockarch.org" # Base URL for DIMES application RESTRICTED_IN_CONTAINER = False # Fetch a list of restricted items in the same container as the requested item. OFFSITE_BUILDINGS = ["Armonk", "Greenrock"] # Names of offsite buildings, which will be added to locations (list of strings) RESOURCE_ID_SEPARATOR = ':' +USE_LOCATION_TITLE = False # Use the title field from a top container location diff --git a/request_broker/settings.py b/request_broker/settings.py index 2ac6362..8a21c3c 100644 --- a/request_broker/settings.py +++ b/request_broker/settings.py @@ -169,4 +169,5 @@ RESTRICTED_IN_CONTAINER = config.RESTRICTED_IN_CONTAINER OFFSITE_BUILDINGS = getattr(config, 'OFFSITE_BUILDINGS', []) +USE_LOCATION_TITLE = config.USE_LOCATION_TITLE RESOURCE_ID_SEPARATOR = config.RESOURCE_ID_SEPARATOR From fb4aae682a4c7c8519373edd3bf69e51be640ac1 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Wed, 5 Jul 2023 15:12:32 -0400 Subject: [PATCH 2/3] linting --- process_request/helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/process_request/helpers.py b/process_request/helpers.py index 87d0177..8cccc29 100644 --- a/process_request/helpers.py +++ b/process_request/helpers.py @@ -69,13 +69,13 @@ def make_short_location(loc_data): if loc_data.get("building") in settings.OFFSITE_BUILDINGS: location_list.insert(0, loc_data["building"]) return ".".join(location_list) - + def use_full_location(loc_data): location_list = loc_data.get("title", "").strip() return location_list locations = None - if settings.USE_LOCATION_TITLE == True: + if getattr(settings, 'USE_LOCATION_TITLE', False): if top_container_info.get("container_locations"): locations = ",".join([use_full_location(c["_resolved"]) for c in top_container_info.get("container_locations")]) else: From 7058adac9f1bbbe0fe246f8bfbab85bd67a68327 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Wed, 5 Jul 2023 15:14:55 -0400 Subject: [PATCH 3/3] add default value to get, removing conditional --- process_request/helpers.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/process_request/helpers.py b/process_request/helpers.py index 8cccc29..6ee3f65 100644 --- a/process_request/helpers.py +++ b/process_request/helpers.py @@ -76,11 +76,9 @@ def use_full_location(loc_data): locations = None if getattr(settings, 'USE_LOCATION_TITLE', False): - if top_container_info.get("container_locations"): - locations = ",".join([use_full_location(c["_resolved"]) for c in top_container_info.get("container_locations")]) + locations = ",".join([use_full_location(c["_resolved"]) for c in top_container_info.get("container_locations", [])]) else: - if top_container_info.get("container_locations"): - locations = ",".join([make_short_location(c["_resolved"]) for c in top_container_info.get("container_locations")]) + locations = ",".join([make_short_location(c["_resolved"]) for c in top_container_info.get("container_locations", [])]) return locations