Skip to content

Commit

Permalink
feat(templates): add link_to_reference_on templatetag
Browse files Browse the repository at this point in the history
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
  • Loading branch information
b1rger committed Jun 28, 2023
1 parent 59648a2 commit 0ba85eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script src="https://unpkg.com/[email protected]"></script>
<a href="{% url "apis_bibsonomy:referenceonlist" content_type object_pk %}"
{% if modal %}
hx-get="{% url "apis_bibsonomy:referenceonlist" content_type object_pk %}"
hx-target="#modal-here"
data-toggle="modal"
data-target="#referenceModal"
{% endif %}
><i data-feather="book-open"></i></a>
10 changes: 10 additions & 0 deletions apis_bibsonomy/templatetags/bibsonomy_templatetags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django import template
from apis_bibsonomy.forms import ReferenceForm
from django.contrib.contenttypes.models import ContentType

register = template.Library()

Expand All @@ -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,
}

0 comments on commit 0ba85eb

Please sign in to comment.