Skip to content

Commit

Permalink
Update serialization: separate seeAlso and related
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Dec 5, 2023
1 parent 87f80b4 commit 374f419
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
33 changes: 31 additions & 2 deletions apps/iiif/manifests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,37 @@ def related_links(self):
:return: List of links related to Manifest
:rtype: list
"""
links = [link.link for link in self.relatedlink_set.all()]
links.append(self.get_volume_url())
links = [
{
"@id": link.link,
"format": link.format,
} if link.format else link.link
for link in self.relatedlink_set.all()
]
links.append({
"@id": self.get_volume_url(),
"format": "text/html"
})
return links

@property
def see_also_links(self):
"""List of links for IIIF v2 'seeAlso' field (structured data).
:return: List of links to structured data describing Manifest
:rtype: list
"""
links = []
for link in self.relatedlink_set.all():
if link.data_type.lower() == "dataset":
links.append(
{
"@id": link.link,
"format": link.format,
}
if link.format
else link.link
)
return links

# TODO: Is this needed? It doesn't seem to be called anywhere.
Expand Down
2 changes: 1 addition & 1 deletion apps/iiif/manifests/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_serialized_related_links(self):
[manifest]
)
)
assert 'seeAlso' not in no_links.keys()
assert not no_links['seeAlso']

link = RelatedLink(link='images.org', manifest=manifest)
link.save()
Expand Down
5 changes: 2 additions & 3 deletions apps/iiif/serializers/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ def get_dump_object(self, obj):
)
)
}
]
],
"seeAlso": obj.see_also_links,
}
if obj.relatedlink_set.exists():
data["seeAlso"] = [related.link for related in obj.relatedlink_set.all()]
return data
return None

Expand Down

0 comments on commit 374f419

Please sign in to comment.