From 5389f425ceb5e78ca6e48dd36bf33225684528a3 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Wed, 12 May 2021 13:55:47 +0200 Subject: [PATCH] mark_safe display_websites & display_addresses --- orchestra/contrib/domains/admin.py | 6 +++++- orchestra/utils/html.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/orchestra/contrib/domains/admin.py b/orchestra/contrib/domains/admin.py index 47b5e14d..f20849dd 100644 --- a/orchestra/contrib/domains/admin.py +++ b/orchestra/contrib/domains/admin.py @@ -3,6 +3,8 @@ from django.urls import reverse from django.db import models from django.db.models.functions import Concat, Coalesce from django.templatetags.static import static +from django.utils.html import format_html +from django.utils.safestring import mark_safe from django.utils.translation import ugettext, ugettext_lazy as _ from orchestra.admin import ExtendedModelAdmin @@ -83,6 +85,7 @@ class DomainAdmin(AccountAdminMixin, ExtendedModelAdmin): display_is_top.boolean = True display_is_top.admin_order_field = 'top' + @mark_safe def display_websites(self, domain): if apps.isinstalled('orchestra.contrib.websites'): websites = domain.websites.all() @@ -92,7 +95,7 @@ class DomainAdmin(AccountAdminMixin, ExtendedModelAdmin): site_link = get_on_site_link(website.get_absolute_url()) admin_url = change_url(website) title = _("Edit website") - link = '%s %s' % ( + link = format_html('{} {}', admin_url, title, website.name, site_link) links.append(link) return '
'.join(links) @@ -108,6 +111,7 @@ class DomainAdmin(AccountAdminMixin, ExtendedModelAdmin): display_websites.short_description = _("Websites") display_websites.allow_tags = True + @mark_safe def display_addresses(self, domain): if apps.isinstalled('orchestra.contrib.mailboxes'): add_url = reverse('admin:mailboxes_address_add') diff --git a/orchestra/utils/html.py b/orchestra/utils/html.py index f888c256..c8741542 100644 --- a/orchestra/utils/html.py +++ b/orchestra/utils/html.py @@ -1,6 +1,7 @@ import textwrap from django.templatetags.static import static +from django.utils.html import format_html from django.utils.translation import ugettext_lazy as _ from orchestra.utils.sys import run @@ -31,6 +32,6 @@ def get_on_site_link(url): context = { 'title': _("View on site %s") % url, 'url': url, - 'image': '' % static('orchestra/images/view-on-site.png'), + 'image': format_html('', static('orchestra/images/view-on-site.png')), } - return '%(image)s' % context + return format_html('{image}', **context)