feat: Add domain customtag

This commit is contained in:
moanos [he/him] 2024-10-05 11:05:33 +02:00
parent c3646e6334
commit 864c76bc21
2 changed files with 20 additions and 1 deletions

View File

@ -48,7 +48,14 @@
<td>{{ adoption_notice.searching_since }}</td>
<td>{{ adoption_notice.last_checked | date:'d. F Y' }}</td>
{% if adoption_notice.further_information %}
<td>{{ adoption_notice.link_to_more_information | safe }}</td>
<td>
<form method="get" action="{% url 'external-site' %}">
<input type="hidden" name="url" value="adoption_notice.further_information">
<button class="btn" type="submit" id="submit">
{{ adoption_notice.further_information | domain }} <i class="fa-solid fa-arrow-up-right-from-square"></i>
</button>
</form>
</td>
{% else %}
<td>-</td>
{% endif %}

View File

@ -4,6 +4,7 @@ from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
from notfellchen import settings
from urllib.parse import urlparse
register = template.Library()
@ -56,6 +57,17 @@ def pointdecimal(value):
except ValueError:
return value
@register.filter
@stringfilter
def domain(url):
try:
domain = urlparse(url).netloc
if domain.startswith("www."):
return domain[4:]
return domain
except ValueError:
return url
@register.simple_tag
def settings_value(name):
return getattr(settings, name)