summaryrefslogtreecommitdiffstats
path: root/core/ld.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/ld.py')
-rw-r--r--core/ld.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/ld.py b/core/ld.py
index 346708c..6692dab 100644
--- a/core/ld.py
+++ b/core/ld.py
@@ -414,6 +414,18 @@ def canonicalise(json_data: Dict, include_security: bool = False) -> Dict:
return jsonld.compact(jsonld.expand(json_data), context)
+def get_list(container, key) -> List:
+ """
+ Given a JSON-LD value (that can be either a list, or a dict if it's just
+ one item), always returns a list"""
+ if key not in container:
+ return []
+ value = container[key]
+ if not isinstance(value, list):
+ return [value]
+ return value
+
+
def format_ld_date(value: datetime.datetime) -> str:
return value.strftime(DATETIME_FORMAT)