Skip to content

Commit

Permalink
Serialize metadata according to IIIF spec
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Dec 11, 2023
1 parent 533458e commit d1b0c1d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions apps/iiif/serializers/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ def start_serialization(self):
def end_serialization(self):
self.stream.write('')

def serialize_metadata(self, obj):
"""Convert metadata on object into list of {label, value} dicts"""
if isinstance(obj.metadata, list):
# most common case: metadata is already a list of {label, value} dicts
return obj.metadata
elif isinstance(obj.metadata, dict):
# convert dict into list of label/value pair dicts
return [{"label": key, "value": val} for (key, val) in obj.metadata.items()]
else:
return []

def get_dump_object(self, obj):
# TODO: Raise error if version is not v2 or v3
if self.version == 'v2' or self.version is None:
Expand Down Expand Up @@ -69,10 +80,6 @@ def get_dump_object(self, obj):
"label": "Publication Date",
"value": obj.published_date
},
{
"label": "Notes",
"value": obj.metadata
},
{
"label": "Record Created",
"value": obj.created_at
Expand All @@ -92,7 +99,9 @@ def get_dump_object(self, obj):
{
"label": "Export Date",
"value": self.exportdate
}
},
# unpack serialized metadata (list of label, value pairs)
*self.serialize_metadata(obj),
],
"description": obj.summary,
"related": obj.related_links,
Expand Down

0 comments on commit d1b0c1d

Please sign in to comment.