Skip to content

Commit

Permalink
Overwrite with fulfill link in FormatWork
Browse files Browse the repository at this point in the history
  • Loading branch information
Apophenia committed Feb 2, 2024
1 parent 4cbc34e commit a48dd03
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def formatWorkOutput(
showAll,
dbClient,
formats=formats,
reader=reader
reader=reader,
request=request
)

cls.addWorkMeta(outWork, highlights=highlights)
Expand All @@ -171,30 +172,28 @@ def formatWorkOutput(
#Formatted work with a specific format given
elif formats != None and identifiers == None:
formattedWork = cls.formatWork(
works, None, showAll, dbClient, formats=formats, reader=reader
works, None, showAll, dbClient, formats=formats, reader=reader, request=request
)

formattedWork['editions'].sort(
key=lambda x: x['publication_date']
if x['publication_date'] else 9999
)

return formattedWork
#Formatted work with no format specified
else:
formattedWork = cls.formatWork(
works, None, showAll, dbClient, reader=reader
works, None, showAll, dbClient, reader=reader, request=request
)

formattedWork['editions'].sort(
key=lambda x: x['publication_date']
if x['publication_date'] else 9999
)

return formattedWork

@classmethod
def formatWork(cls, work, editionIds, showAll, dbClient=None, formats=None, reader=None):
def formatWork(cls, work, editionIds, showAll, dbClient=None, formats=None, reader=None, request=None):
workDict = dict(work)
workDict['edition_count'] = len(work.editions)
workDict['inCollections'] = cls.checkEditionInCollection(work, None, dbClient=dbClient)
Expand Down Expand Up @@ -224,6 +223,10 @@ def formatWork(cls, work, editionIds, showAll, dbClient=None, formats=None, read
None, [e for _, e in orderedEds.items()])
)

for edition in workDict['editions']:
for item in edition['items']:
# Map over item links and patch with pre-signed URL where necessary
item['links']= list(map(APIUtils.replacePrivateLinkUrl, item['links'], repeat(request)))
return workDict

@classmethod
Expand Down

0 comments on commit a48dd03

Please sign in to comment.