Handle HTML safe rendering on webapps & miscellaneous

Drop `allow_tags` attribute which has been removed on Django 2.0
This commit is contained in:
Santiago L 2021-05-21 11:17:06 +02:00
parent 4f695c2e6e
commit 06c226d302
2 changed files with 4 additions and 20 deletions

View file

@ -2,6 +2,7 @@ from django import forms
from django.contrib import admin from django.contrib import admin
from django.urls import reverse from django.urls import reverse
from django.db import models from django.db import models
from django.utils.html import format_html
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -38,15 +39,13 @@ class MiscServiceAdmin(ExtendedModelAdmin):
actions = (disable, enable) actions = (disable, enable)
def display_name(self, misc): def display_name(self, misc):
return '<span title="%s">%s</span>' % (misc.description, misc.name) return format_html('<span title="{}">{}</span>', misc.description, misc.name)
display_name.short_description = _("name") display_name.short_description = _("name")
display_name.allow_tags = True
display_name.admin_order_field = 'name' display_name.admin_order_field = 'name'
def display_verbose_name(self, misc): def display_verbose_name(self, misc):
return '<span title="%s">%s</span>' % (misc.description, misc.verbose_name) return format_html('<span title="{}">{}</span>', misc.description, misc.verbose_name)
display_verbose_name.short_description = _("verbose name") display_verbose_name.short_description = _("verbose name")
display_verbose_name.allow_tags = True
display_verbose_name.admin_order_field = 'verbose_name' display_verbose_name.admin_order_field = 'verbose_name'
def num_instances(self, misc): def num_instances(self, misc):

View file

@ -89,23 +89,8 @@ class WebAppAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedModelAdmin)
try: try:
return webapp.type_instance.get_detail() return webapp.type_instance.get_detail()
except KeyError: except KeyError:
return "<span style='color:red;'>Not available</span>" return mark_safe("<span style='color:red;'>Not available</span>")
display_detail.short_description = _("detail") display_detail.short_description = _("detail")
display_detail.allow_tags = True
# def get_form(self, request, obj=None, **kwargs):
# form = super(WebAppAdmin, self).get_form(request, obj, **kwargs)
# if obj:
#
# def formfield_for_dbfield(self, db_field, **kwargs):
# """ Make value input widget bigger """
# if db_field.name == 'type':
# # Help text based on select widget
# kwargs['widget'] = DynamicHelpTextSelect(
# 'this.id.replace("name", "value")', self.TYPE_HELP_TEXT
# )
# kwargs['help_text'] = self.TYPE_HELP_TEXT.get(db_field.default, '')
# return super(WebAppAdmin, self).formfield_for_dbfield(db_field, **kwargs)
admin.site.register(WebApp, WebAppAdmin) admin.site.register(WebApp, WebAppAdmin)