abstract true/false renderings

pull/104/head
mariusrklein 11 months ago
parent edd21e6ac3
commit b665d4ed45

@ -1,5 +1,6 @@
{% extends "admin/base_site.html" %}
{% load i18n admin_urls static %}
{% load overview_extras %}
{% block extrahead %}
{{ block.super }}
@ -47,8 +48,7 @@
{{ bill.paid_by.name }}
</td>
<td>
<span style="font-weight: bold; color: {{ bill.paid_by.iban_valid|yesno:'#bcd386,#dba4a4' }};" class="{{ bill.paid_by.iban_valid|yesno:'icon-tick,icon-cross' }}"></span>
{% if not bill.paid_by.iban_valid %} <a target="_blank" href='/kompassmembers/member/{{ bill.paid_by.id }}/change/#/tab/module_1/'>{% trans "Change here" %}</a> {% endif %}
{{ bill.paid_by.iban_valid|render_bool }}
</td>
</tr>
{% endfor %}

@ -1,5 +1,6 @@
{% extends "admin/base_site.html" %}
{% load i18n admin_urls static %}
{% load overview_extras %}
{% block extrahead %}
{{ block.super }}
@ -56,8 +57,7 @@ cost plan!
{{ bill.paid_by.name }}
</td>
<td>
<span style="font-weight: bold; color: {{ bill.paid_by.iban_valid|yesno:'#bcd386,#dba4a4' }};" class="{{ bill.paid_by.iban_valid|yesno:'icon-tick,icon-cross' }}"></span>
{% if not bill.paid_by.iban_valid %} <a target="_blank" href='/kompassmembers/member/{{ bill.paid_by.id }}/change/#/tab/module_1/'>{% trans "Change here" %}</a> {% endif %}
{{ bill.paid_by.iban_valid|render_bool }}
</td>
</tr>
{% endfor %}

@ -1,4 +1,5 @@
from django import template
from django.utils.html import format_html
register = template.Library()
@ -15,3 +16,19 @@ def has_attendee_wrapper(klettertreff, member):
@register.simple_tag
def has_jugendleiter_wrapper(klettertreff, jugendleiter):
return blToColor(klettertreff.has_jugendleiter(jugendleiter))
@register.filter
def render_bool(boolean_value):
if not isinstance(boolean_value, bool):
raise ValueError(f"""Custom Filter 'render_bool': Supplied value '{boolean_value}' is not bool, but {type(boolean_value)}.""")
if boolean_value: # True is a green tick
color = "#bcd386"
htmlclass = "icon-tick"
else: # False is a red cross
color = "#dba4a4"
htmlclass = "icon-cross"
return format_html(f"""<span style="font-weight: bold; color: {color};"
class="{htmlclass}"></span>""")
Loading…
Cancel
Save