Skip to content

Commit

Permalink
#222: Use ASnake to format the resource id
Browse files Browse the repository at this point in the history
  • Loading branch information
ctgraham committed Sep 1, 2022
1 parent 8d69d04 commit 97d8d5f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion process_request/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import inflect
import shortuuid
from asnake.utils import get_date_display, get_note_text, text_in_note
from asnake.utils import format_resource_id, get_date_display, get_note_text, text_in_note
from django.conf import settings
from ordered_set import OrderedSet

Expand Down Expand Up @@ -439,3 +439,11 @@ def resolve_ref_id(repo_id, ref_id, client):
aspace_obj = aspace_objs['archival_objects'][0]['ref']
resolved = identifier_from_uri(aspace_obj)
return resolved


def get_formatted_resource_id(resource, client):
"""Gets a formatted resource id from the resource
Concatenates the resource id parts using the separator from the config
"""
return format_resource_id(resource, client, settings.RESOURCE_ID_SEPARATOR)
7 changes: 4 additions & 3 deletions process_request/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from django.conf import settings
from django.core.mail import send_mail

from .helpers import (get_container_indicators, get_dates, get_parent_title,
get_preferred_format, get_resource_creators,
from .helpers import (get_container_indicators, get_dates, get_formatted_resource_id,
get_parent_title, get_preferred_format, get_resource_creators,
get_restricted_in_container, get_rights_info, get_size,
get_url, list_chunks)

Expand Down Expand Up @@ -58,6 +58,7 @@ def get_data(self, uri_list, dimes_baseurl):
parent = self.strip_tags(get_parent_title(item_json.get("ancestors")[0].get("_resolved"))) if len(item_json.get("ancestors")) > 1 else None
format, container, subcontainer, location, barcode, container_uri = get_preferred_format(item_json)
restrictions, restrictions_text = get_rights_info(item_json, aspace.client)
resource_id = get_formatted_resource_id(item_collection, aspace.client)
data.append({
"creators": get_resource_creators(item_collection, aspace.client),
"restrictions": restrictions,
Expand All @@ -66,7 +67,7 @@ def get_data(self, uri_list, dimes_baseurl):
"collection_name": self.strip_tags(item_collection.get("title")),
"parent": parent,
"dates": get_dates(item_json, aspace.client),
"resource_id": item_collection.get("id_0"),
"resource_id": resource_id,
"title": self.strip_tags(item_json.get("display_string")),
"uri": item_json["uri"],
"dimes_url": get_url(item_json, dimes_baseurl, aspace.client),
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 @@ -22,3 +22,4 @@ DEFAULT_FROM_EMAIL = "${DEFAULT_FROM_EMAIL}"
DIMES_HOSTNAME = "${DIMES_HOSTNAME}"
RESTRICTED_IN_CONTAINER = ${RESTRICTED_IN_CONTAINER}
OFFSITE_BUILDINGS = ${OFFSITE_BUILDINGS}
RESOURCE_ID_SEPARATOR = ${RESOURCE_ID_SEPARATOR}
1 change: 1 addition & 0 deletions request_broker/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ DEFAULT_FROM_EMAIL = "dimes@example.com" # user that should be set as the sende
DIMES_HOSTNAME = "dimes.rockarch.org" # Hostname 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 = ':'
1 change: 1 addition & 0 deletions request_broker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@

RESTRICTED_IN_CONTAINER = config.RESTRICTED_IN_CONTAINER
OFFSITE_BUILDINGS = getattr(config, 'OFFSITE_BUILDINGS', [])
RESOURCE_ID_SEPARATOR = config.RESOURCE_ID_SEPARATOR

0 comments on commit 97d8d5f

Please sign in to comment.