From 0ba85eb5284fd1ce376a40f7ddfcdc50464eb4b3 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Tue, 27 Jun 2023 10:42:29 +0200 Subject: [PATCH] feat(templates): add link_to_reference_on templatetag This commit introduces a `link_to_reference_on` reference tag, which can be used to include link to the referenceonview from other modules. The tag expects a model instance as argument. It then creates a link to the reference on view. If the `modal` argument is passed to the templatetag, the created link uses htmx to fill a modal with the id #modal-here --- .../apis_bibsonomy/link_to_reference_on_tag.html | 9 +++++++++ apis_bibsonomy/templatetags/bibsonomy_templatetags.py | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 apis_bibsonomy/templates/apis_bibsonomy/link_to_reference_on_tag.html diff --git a/apis_bibsonomy/templates/apis_bibsonomy/link_to_reference_on_tag.html b/apis_bibsonomy/templates/apis_bibsonomy/link_to_reference_on_tag.html new file mode 100644 index 0000000..498a54c --- /dev/null +++ b/apis_bibsonomy/templates/apis_bibsonomy/link_to_reference_on_tag.html @@ -0,0 +1,9 @@ + + diff --git a/apis_bibsonomy/templatetags/bibsonomy_templatetags.py b/apis_bibsonomy/templatetags/bibsonomy_templatetags.py index fa8c0d6..2c08ea2 100644 --- a/apis_bibsonomy/templatetags/bibsonomy_templatetags.py +++ b/apis_bibsonomy/templatetags/bibsonomy_templatetags.py @@ -1,5 +1,6 @@ from django import template from apis_bibsonomy.forms import ReferenceForm +from django.contrib.contenttypes.models import ContentType register = template.Library() @@ -16,3 +17,12 @@ def bibsonomy_list(content_type=None, object_pk=None, attribute_name=None): c_dict = {'content_type': content_type, 'object_pk': object_pk, 'attribute_name': attribute_name} form = ReferenceForm(**c_dict) return {"form": form} + + +@register.inclusion_tag('apis_bibsonomy/link_to_reference_on_tag.html', takes_context=False) +def link_to_reference_on(obj=None, modal=False): + return { + "modal": modal, + "object_pk": obj.pk, + "content_type": ContentType.objects.get_for_model(obj).id, + }