From 865754abe1926d7fde4e6db6edb4fb24790d8c52 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Thu, 25 Jan 2024 10:41:13 +0100 Subject: [PATCH] fix(collections): add collection_content_objects templatetag This templatetag allows to list collectionobjects an instance is connected to. --- .../collections/templatetags/apis_collections.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apis_core/collections/templatetags/apis_collections.py b/apis_core/collections/templatetags/apis_collections.py index bf33567b9..2c91e4866 100644 --- a/apis_core/collections/templatetags/apis_collections.py +++ b/apis_core/collections/templatetags/apis_collections.py @@ -81,3 +81,15 @@ def collection_object_parent_by_id(context, obj, collectionobject_id): """ collectionobject = SkosCollectionContentObject.objects.get(pk=collectionobject_id) return collection_object_parent(context, obj, collectionobject) + + +@register.simple_tag(takes_context=True) +def collection_content_objects(context, obj, collectionids=None): + content_type = ContentType.objects.get_for_model(obj) + sccos = SkosCollectionContentObject.objects.filter( + content_type=content_type, object_id=obj.id + ) + if collectionids is not None: + ids = collectionids.split(",") + sccos = sccos.filter(collection__id__in=ids) + return sccos