Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add offsite building names to locations #209

Merged
merged 3 commits into from
Aug 3, 2022
Merged
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
1 change: 1 addition & 0 deletions fixtures/locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions fixtures/locations_offsite.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
13 changes: 9 additions & 4 deletions process_request/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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"):
Expand Down
9 changes: 5 additions & 4 deletions process_request/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions request_broker/config.py.deploy
Original file line number Diff line number Diff line change
Expand Up @@ -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}
1 change: 1 addition & 0 deletions request_broker/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions request_broker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,5 @@
("size", "Size"),
("collection_name", "Collection Name"),
("parent", "Parent Collection Name")]

OFFSITE_BUILDINGS = getattr(config, 'OFFSITE_BUILDINGS', [])