Skip to content

Commit 12b8b8f

Browse files
committed
Add accept function for community-submitted records
1 parent 3b52a19 commit 12b8b8f

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

caltechdata_api/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
add_file_links,
55
send_to_community,
66
)
7-
from .caltechdata_edit import caltechdata_edit, caltechdata_unembargo
7+
from .caltechdata_edit import (
8+
caltechdata_edit,
9+
caltechdata_unembargo,
10+
caltechdata_accept,
11+
)
812
from .customize_schema import customize_schema
913
from .get_metadata import get_metadata
1014
from .download_file import download_file, download_url

caltechdata_api/caltechdata_edit.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,43 @@ def caltechdata_unembargo(token, ids, production=False):
1515
print("caltechdaua_unembargo is not yet re-implemented")
1616

1717

18+
def caltechdata_accept(ids, token=None, production=False):
19+
# Accept a record into a community
20+
21+
# If no token is provided, get from RDMTOK environment variable
22+
if not token:
23+
token = os.environ["RDMTOK"]
24+
25+
if production == True:
26+
url = "https://data.caltech.edu"
27+
verify = True
28+
else:
29+
url = "https://data.caltechlibrary.dev"
30+
verify = True
31+
32+
headers = {
33+
"Authorization": "Bearer %s" % token,
34+
"Content-type": "application/json",
35+
}
36+
37+
for idv in ids:
38+
39+
result = requests.get(
40+
url + "/api/records/" + idv + "/draft/review", headers=headers
41+
)
42+
43+
accept_link = result.json()["links"]["actions"]["accept"]
44+
data = comment = {
45+
"payload": {
46+
"content": "This record is accepted automatically with the CaltechDATA API",
47+
"format": "html",
48+
}
49+
}
50+
result = requests.post(accept_link, json=data, headers=headers)
51+
if result.status_code != 200:
52+
raise Exception(result.text)
53+
54+
1855
def caltechdata_edit(
1956
ids,
2057
metadata={},

caltechdata_api/customize_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def grid_to_ror(grid):
1313
# We manually handle some incorrect/redundant GRID Ids
1414
if grid == "grid.451078.f":
1515
ror = "https://ror.org/00hm6j694"
16-
elif grid == 'grid.5805.8':
16+
elif grid == "grid.5805.8":
1717
ror = "https://ror.org/02en5vm52"
1818
else:
1919
url = f"https://api.ror.org/organizations?query.advanced=external_ids.GRID.all:{grid}"
@@ -336,7 +336,7 @@ def customize_schema_rdm(json_record):
336336
funder["id"] = ror
337337
fund.pop("funderIdentifierType")
338338
elif fund["funderIdentifierType"] == "GRID":
339-
#We need this temporarily to round-trip data
339+
# We need this temporarily to round-trip data
340340
ror = grid_to_ror(fund.pop("funderIdentifier"))
341341
funder["id"] = ror
342342
fund.pop("funderIdentifierType")

0 commit comments

Comments
 (0)