Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
dj-kaos-utils / admin_utils.py
Size: Mime:
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.safestring import mark_safe

from .admin import render_anchor_tag


def get_instance_admin_url(obj):
    opts = obj._meta
    return reverse(f'admin:{opts.db_table}_change', args=(obj.pk,))


def render_admin_link(obj, text=None):
    if text is None:
        text = str(obj)
    return mark_safe(render_anchor_tag(get_instance_admin_url(obj), text))


def render_table(data, header):
    return render_to_string('kaos_utils/table.html', dict(data=data, header=header))


def render_image(url, alt="image", height=None):
    return mark_safe(f"""
            <img alt="{alt}" src="{url}" height="{height if height is not None else ''}" />
        """)