admin: add support for extra links
This commit is contained in:
parent
d307d142dc
commit
7178468135
|
@ -5,6 +5,7 @@
|
|||
"editor.tabSize": 2
|
||||
},
|
||||
"cSpell.words": [
|
||||
"SAML",
|
||||
"pyazo"
|
||||
]
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
{% load i18n %}
|
||||
{% load utils %}
|
||||
{% load admin_reflection %}
|
||||
|
||||
{% block title %}
|
||||
{% title %}
|
||||
|
@ -38,6 +39,10 @@
|
|||
<td>
|
||||
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:provider-update' pk=provider.pk %}?back={{ request.get_full_path }}">{% trans 'Edit' %}</a>
|
||||
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:provider-delete' pk=provider.pk %}?back={{ request.get_full_path }}">{% trans 'Delete' %}</a>
|
||||
{% get_links provider as links %}
|
||||
{% for name, href in links.items %}
|
||||
<a class="btn btn-default btn-sm" href="{{ href }}?back={{ request.get_full_path }}">{% trans name %}</a>
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
{% load i18n %}
|
||||
{% load utils %}
|
||||
{% load admin_reflection %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
@ -34,6 +35,10 @@
|
|||
<td>
|
||||
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:source-update' pk=source.uuid %}?back={{ request.get_full_path }}">{% trans 'Edit' %}</a>
|
||||
<a class="btn btn-default btn-sm" href="{% url 'passbook_admin:source-delete' pk=source.uuid %}?back={{ request.get_full_path }}">{% trans 'Delete' %}</a>
|
||||
{% get_links source as links %}
|
||||
{% for name, href in links %}
|
||||
<a class="btn btn-default btn-sm" href="{{ href }}?back={{ request.get_full_path }}">{% trans name %}</a>
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
"""passbook admin templatetags"""
|
||||
import inspect
|
||||
from logging import getLogger
|
||||
|
||||
from django import template
|
||||
from django.db.models import Model
|
||||
|
||||
register = template.Library()
|
||||
LOGGER = getLogger(__name__)
|
||||
|
||||
@register.simple_tag()
|
||||
def get_links(model_instance):
|
||||
"""Find all link_ methods on an object instance, run them and return as dict"""
|
||||
prefix = 'link_'
|
||||
links = {}
|
||||
|
||||
if not isinstance(model_instance, Model):
|
||||
LOGGER.warning("Model %s is not instance of Model", model_instance)
|
||||
return links
|
||||
|
||||
for name, method in inspect.getmembers(model_instance, predicate=inspect.ismethod):
|
||||
if name.startswith(prefix):
|
||||
human_name = name.replace(prefix, '').replace('_', ' ').capitalize()
|
||||
links[human_name] = method()
|
||||
|
||||
return links
|
Reference in New Issue