diff --git a/fixtures/locations.json b/fixtures/locations.json index d2cdaa9..5b2fded 100644 --- a/fixtures/locations.json +++ b/fixtures/locations.json @@ -5,6 +5,7 @@ "container_locations": [ { "_resolved": { + "building": "Rockefeller Archive Center", "title": "Rockefeller Archive Center, Blue Level, Vault 106 [Unit: 66, Shelf: 7]", "room": "Vault 106", "coordinate_1_indicator": "66", diff --git a/fixtures/locations_offsite.json b/fixtures/locations_offsite.json new file mode 100644 index 0000000..8b1e57a --- /dev/null +++ b/fixtures/locations_offsite.json @@ -0,0 +1,16 @@ +{ + "type": "box", + "indicator": "2", + "barcode": "A12345", + "container_locations": [ + { + "_resolved": { + "building": "Armonk", + "title": "Armonk, Vault 1 [Unit: 66, Shelf: 7]", + "room": "Vault 1", + "coordinate_1_indicator": "66", + "coordinate_2_indicator": "7" + } + } + ] +} diff --git a/process_request/helpers.py b/process_request/helpers.py index 5da566b..3b77b03 100644 --- a/process_request/helpers.py +++ b/process_request/helpers.py @@ -3,6 +3,7 @@ import inflect import shortuuid from asnake.utils import get_date_display, get_note_text, text_in_note +from django.conf import settings from ordered_set import OrderedSet CONFIDENCE_RATIO = 97 # Minimum confidence ratio to match against. @@ -50,6 +51,8 @@ def get_file_versions(digital_object): def get_locations(top_container_info): """Gets a string representation of a location for an ArchivesSpace top container. + Adds the building name for offsite locations only. + Args: top_container_info (dict): json for a top container (with resolved container locations) @@ -58,10 +61,12 @@ def get_locations(top_container_info): """ def make_short_location(loc_data): - return ".".join([ - loc_data.get("room", "").strip().replace("Vault ", ""), - loc_data.get("coordinate_1_indicator", "").strip(), - loc_data.get("coordinate_2_indicator", "").strip()]) + location_list = [loc_data.get("room", "").strip().replace("Vault ", ""), + loc_data.get("coordinate_1_indicator", "").strip(), + loc_data.get("coordinate_2_indicator", "").strip()] + if loc_data.get("building") in settings.OFFSITE_BUILDINGS: + location_list.insert(0, loc_data["building"]) + return ".".join(location_list) locations = None if top_container_info.get("container_locations"): diff --git a/process_request/tests.py b/process_request/tests.py index bc8903a..e37f2d8 100644 --- a/process_request/tests.py +++ b/process_request/tests.py @@ -7,7 +7,7 @@ from asnake.aspace import ASpace from django.core import mail from django.http import StreamingHttpResponse -from django.test import TestCase +from django.test import TestCase, override_settings from django.urls import reverse from rest_framework.test import APIRequestFactory @@ -99,10 +99,11 @@ def test_get_file_versions(self): digital_object = {'file_versions': [{'file_uri': uri}]} self.assertEqual(get_file_versions(digital_object), uri) + @override_settings(OFFSITE_BUILDINGS=["Armonk"]) def test_get_locations(self): - obj_data = json_from_fixture("locations.json") - expected_location = "106.66.7" - self.assertEqual(get_locations(obj_data), expected_location) + for fixture, expected in [("locations.json", "106.66.7"), ("locations_offsite.json", "Armonk.1.66.7")]: + obj_data = json_from_fixture(fixture) + self.assertEqual(get_locations(obj_data), expected) def test_get_instance_data(self): obj_data = json_from_fixture("digital_object_instance.json") diff --git a/request_broker/config.py.deploy b/request_broker/config.py.deploy index b80052f..59bdbb4 100644 --- a/request_broker/config.py.deploy +++ b/request_broker/config.py.deploy @@ -20,3 +20,4 @@ EMAIL_USE_TLS = ${EMAIL_USE_TLS} EMAIL_USE_SSL = ${EMAIL_USE_SSL} DEFAULT_FROM_EMAIL = "${DEFAULT_FROM_EMAIL}" DIMES_HOSTNAME = "${DIMES_HOSTNAME}" +OFFSITE_BUILDINGS = ${OFFSITE_BUILDINGS} diff --git a/request_broker/config.py.example b/request_broker/config.py.example index d47060e..186eb94 100644 --- a/request_broker/config.py.example +++ b/request_broker/config.py.example @@ -20,3 +20,4 @@ EMAIL_USE_TLS = 1 # Use TLS connection for email (1 for True, 0 for False) EMAIL_USE_SSL = 0 # Use SSL connection for email (1 for True, 0 for False) DEFAULT_FROM_EMAIL = "dimes@example.com" # user that should be set as the sender DIMES_HOSTNAME = "dimes.rockarch.org" # Hostname for DIMES application +OFFSITE_BUILDINGS = ["Armonk", "Greenrock"] # Names of offsite buildings, which will be added to locations (list of strings) diff --git a/request_broker/settings.py b/request_broker/settings.py index 6a61e1b..d2e6561 100644 --- a/request_broker/settings.py +++ b/request_broker/settings.py @@ -162,3 +162,5 @@ ("size", "Size"), ("collection_name", "Collection Name"), ("parent", "Parent Collection Name")] + +OFFSITE_BUILDINGS = getattr(config, 'OFFSITE_BUILDINGS', [])