{% load add_preserved_filters from admin_urls %}

{% with tool_label=tool.label|lower %}
  {% if tool.button_type == 'a' %}
    <a href="{% add_preserved_filters action_url %}"
      title="{{ tool.standard_attrs.title }}"
      {% for k, v in tool.custom_attrs.items %}
        {{ k }}="{{ v }}"
      {% endfor %}
      class="{{ tool.standard_attrs.class }}{% if tool_label == 'discover' %} addlink discover-action{% endif %}"
    >
      {{ tool.label|capfirst }}
    </a>
  {% elif tool.button_type == 'form' %}
    <form method="post" action="{% add_preserved_filters action_url %}">
      {% csrf_token %}
      <a href="#" onclick="this.parentNode.submit(); return false;"
        title="{{ tool.standard_attrs.title }}"
        {% for k, v in tool.custom_attrs.items %}
          {{ k }}="{{ v }}"
        {% endfor %}
        class="{{ tool.standard_attrs.class }}{% if tool_label == 'discover' %} addlink discover-action{% endif %}"
      >
        {{ tool.label|capfirst }}
      </a>
    </form>
  {% endif %}
{% endwith %}
