Skip to content

Commit

Permalink
Merge pull request #4 from acdh-oeaw/linkify-in-list
Browse files Browse the repository at this point in the history
Linkify template tag and Place table update
  • Loading branch information
gythaogg authored Apr 22, 2024
2 parents 8c92f38 + 385da55 commit f263412
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apis_ontology/tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import django_tables2 as tables
from apis_core.apis_entities.tables import AbstractEntityTable
from django_tables2.utils import A

from .templatetags.linkify_list import render_links
from .models import Place


Expand All @@ -14,3 +16,6 @@ class Meta:
linkify=lambda record: record.get_edit_url(),
empty_values=[],
)

def render_external_links(self, value):
return render_links(value)
16 changes: 16 additions & 0 deletions apis_ontology/templatetags/linkify_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django import template
from django.utils.safestring import mark_safe

register = template.Library()


@register.filter
def render_links(value):
if not value:
return ""

links = [link.strip() for link in value.split("\n") if link.strip()]
rendered_links = "<br>".join(
f'<a href="{link}" target="_blank">{link}</a>' for link in links
)
return mark_safe(rendered_links)

0 comments on commit f263412

Please sign in to comment.