From: Stephen Finucane Date: Fri, 10 Apr 2020 16:34:15 +0000 (+0100) Subject: templatetags: Add 'site_admins' tag X-Git-Tag: v3.1.0~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d45df8c0f1cec91c682c894ae0196b57741bb5b7;p=thirdparty%2Fpatchwork.git templatetags: Add 'site_admins' tag This lets us avoid complex templating. Signed-off-by: Stephen Finucane --- diff --git a/patchwork/templates/patchwork/optin-request.html b/patchwork/templates/patchwork/optin-request.html index 3384c462..36744c26 100644 --- a/patchwork/templates/patchwork/optin-request.html +++ b/patchwork/templates/patchwork/optin-request.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load admins %} + {% block title %}Opt-in{% endblock %} {% block heading %}Opt-in{% endblock %} @@ -40,11 +42,7 @@ {% if error and admins %}

- If you are having trouble opting in, please email -{% for admin in admins %} -{% if admins|length > 1 and forloop.last %} or {% endif %} -{{ admin.0 }} <{{ admin.1 }}>{% if admins|length > 2 and not forloop.last %}, {% endif %} -{% endfor %} + If you are having trouble opting in, please email {% site_admins %}.

{% endif %} {% endif %} diff --git a/patchwork/templates/patchwork/optout-request.html b/patchwork/templates/patchwork/optout-request.html index 7396fd36..a89f72bb 100644 --- a/patchwork/templates/patchwork/optout-request.html +++ b/patchwork/templates/patchwork/optout-request.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% load admins %} + {% block title %}Opt-out{% endblock %} {% block heading %}Opt-out{% endblock %} @@ -42,11 +44,7 @@ {% if error and admins %}

- If you are having trouble opting out, please email -{% for admin in admins %} -{% if admins|length > 1 and forloop.last %} or {% endif %} -{{ admin.0 }} <{{ admin.1 }}>{% if admins|length > 2 and not forloop.last %}, {% endif %} -{% endfor %} + If you are having trouble opting out, please email {% site_admins %}.

{% endif %} {% endif %} diff --git a/patchwork/templatetags/admins.py b/patchwork/templatetags/admins.py new file mode 100644 index 00000000..07a33e29 --- /dev/null +++ b/patchwork/templatetags/admins.py @@ -0,0 +1,27 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2020 Stephen Finucane +# +# SPDX-License-Identifier: GPL-2.0-or-later + +from django.conf import settings +from django import template +from django.utils.safestring import mark_safe + + +register = template.Library() + + +@register.simple_tag() +def site_admins(): + admins = [ + f'{admin[0]} <{admin[1]}>' + for admin in settings.ADMINS + ] + + if not admins: + return '' + + if len(admins) == 1: + return mark_safe(admins[0]) + + return mark_safe(', '.join(admins[:-2]) + admins[-2] + ' or ' + admins[-1])