def hijack_field(self, obj): hijack_methods = getattr(settings, 'ALLOWED_HIJACKING_USER_ATTRIBUTES', ('user_id', )) if 'user_id' in hijack_methods: hijack_url = reverse('login_with_id', args=(obj.pk, )) elif 'email' in hijack_methods: hijack_url = reverse('login_with_email', args=(obj.email, )) elif 'username': hijack_url = reverse('login_with_username', args=(obj.username, )) else: raise ImproperlyConfigured( "`ALLOWED_HIJACKING_USER_ATTRIBUTES` needs to be " "properly defined") return format_html('<a href="{}" class="button">Hijack {}</a>', hijack_url, obj)
def test_format_html(self): """ Test: format_html url: https://github.com/django/django/blob/stable/1.8.x/tests/utils_tests/test_html.py#L44-L53 """ from django.utils import html from compat import format_html self.assertEqual( format_html("{0} {1} {third} {fourth}", "< Dangerous >", html.mark_safe("<b>safe</b>"), third="< dangerous again", fourth=html.mark_safe("<i>safe again</i>")), "< Dangerous > <b>safe</b> < dangerous again <i>safe again</i>" )
def test_format_html(self): """ Test: format_html url: https://github.com/django/django/blob/stable/1.8.x/tests/utils_tests/test_html.py#L44-L53 """ from django.utils import html from compat import format_html self.assertEqual( format_html("{0} {1} {third} {fourth}", "< Dangerous >", html.mark_safe("<b>safe</b>"), third="< dangerous again", fourth=html.mark_safe("<i>safe again</i>") ), "< Dangerous > <b>safe</b> < dangerous again <i>safe again</i>" )
from django.contrib.admin import AdminSite from django.utils.translation import ugettext_lazy from django.contrib import admin from compat import format_html from django.core import urlresolvers class AdminSiteTitles(AdminSite): # Text to put at the end of each page's <title>. site_title = ugettext_lazy('FreeSWITCH site admin') # Text to put in each page's <h1>. site_header = ugettext_lazy('FreeSWITCH Service administration') # Text to put at the top of the admin index page. index_title = ugettext_lazy('Dashboard administration') # admin.site = AdminSiteTitles() admin.site.site_title = format_html('FreeSWITCH site admin') admin.site.site_header = format_html( '<a href="' + urlresolvers.reverse('admin:index') + '"><span style="font-size:18px">FreeSWITCH <b style="font-size:18px">Service</b></a> administration</span>' ) admin.site.index_title = format_html('Dashboard Administration')