|
8 | 8 | from django.db import models
|
9 | 9 | from django.template.response import TemplateResponse
|
10 | 10 | from django.utils import timezone
|
11 |
| -from django.utils.html import escape |
12 | 11 | from django.utils.html import format_html
|
13 |
| -from django.utils.safestring import mark_safe |
14 | 12 | from django.utils.translation import gettext_lazy as _
|
15 | 13 | from djstripe.models import Invoice
|
16 | 14 | from simple_history.admin import SimpleHistoryAdmin
|
@@ -190,9 +188,11 @@ def report(self, instance):
|
190 | 188 | if not instance.pk:
|
191 | 189 | return "" # pragma: no cover
|
192 | 190 |
|
193 |
| - name = escape(instance.name) |
194 |
| - url = instance.get_absolute_url() |
195 |
| - return mark_safe(f'<a href="{url}">{name}</a> Report') |
| 191 | + return format_html( |
| 192 | + '<a href="{}">{}</a>', |
| 193 | + instance.get_absolute_url(), |
| 194 | + f"{instance.name} Report", |
| 195 | + ) |
196 | 196 |
|
197 | 197 |
|
198 | 198 | class CampaignInline(admin.TabularInline):
|
@@ -296,10 +296,10 @@ def report(self, instance):
|
296 | 296 | if not instance.pk:
|
297 | 297 | return "" # pragma: no cover
|
298 | 298 |
|
299 |
| - return mark_safe( |
300 |
| - '<a href="{url}">{name}</a>'.format( |
301 |
| - name=escape(instance.name) + " Report", url=instance.get_absolute_url() |
302 |
| - ) |
| 299 | + return format_html( |
| 300 | + '<a href="{}">{}</a>', |
| 301 | + instance.get_absolute_url(), |
| 302 | + f"{instance.name} Report", |
303 | 303 | )
|
304 | 304 |
|
305 | 305 | def stripe_customer(self, obj):
|
@@ -344,8 +344,10 @@ def ad_image(self, obj):
|
344 | 344 | if not obj.image:
|
345 | 345 | return ""
|
346 | 346 |
|
347 |
| - return mark_safe( |
348 |
| - f'<img src="{obj.image.url}" style="max-width: {self.MAX_IMAGE_WIDTH}px" />' |
| 347 | + return format_html( |
| 348 | + '<img src="{}" style="max-width: {}px" />', |
| 349 | + obj.image.url, |
| 350 | + self.MAX_IMAGE_WIDTH, |
349 | 351 | )
|
350 | 352 |
|
351 | 353 | def ctr(self, obj):
|
@@ -774,11 +776,10 @@ def campaign_report(self, instance):
|
774 | 776 | if not instance.pk or not instance.advertiser:
|
775 | 777 | return "" # pragma: no cover
|
776 | 778 |
|
777 |
| - return mark_safe( |
778 |
| - '<a href="{url}">{name}</a>'.format( |
779 |
| - name=escape(instance.name) + " Report", |
780 |
| - url=instance.advertiser.get_absolute_url(), |
781 |
| - ) |
| 779 | + return format_html( |
| 780 | + '<a href="{}">{}</a>', |
| 781 | + instance.advertiser.get_absolute_url(), |
| 782 | + f"{instance.name} Report", |
782 | 783 | )
|
783 | 784 |
|
784 | 785 | def num_ads(self, obj):
|
@@ -949,8 +950,10 @@ class AdBaseAdmin(RemoveDeleteMixin, admin.ModelAdmin):
|
949 | 950 |
|
950 | 951 | def page_url(self, instance):
|
951 | 952 | if instance.url:
|
952 |
| - return mark_safe( |
953 |
| - '<a href="{url}">{url}</a>'.format(url=escape(instance.url)) |
| 953 | + return format_html( |
| 954 | + '<a href="{}">{}</a>', |
| 955 | + instance.url, |
| 956 | + instance.url, |
954 | 957 | )
|
955 | 958 | return None
|
956 | 959 |
|
|
0 commit comments