{% extends "admin/change_form.html" %}
{% load add_preserved_filters from admin_urls %}
{% load static %}

{% block extrastyle %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'django_object_actions/css/style.css' %}">
{% endblock %}

{% block object-tools-items %}
  {% for tool in objectactions %}
    {% if not tool.has_inline_form %}
      <li class="objectaction-item" data-tool-name="{{ tool.name }}">
        {% url tools_view_name pk=object_id tool=tool.name as action_url %}
        <form name="{{ tool.name }}__form" method="post" action="{% add_preserved_filters action_url %}">
          {% csrf_token %}
          <a href="javascript:window.document.forms['{{ tool.name }}__form'].submit()" title="{{ tool.standard_attrs.title }}"
            {% for k, v in tool.custom_attrs.items %}
              {{ k }}="{{ v }}"
            {% endfor %}
            class="{{ tool.standard_attrs.class }}">
            {{ tool.label|capfirst }}
          </a>
        </form>
      </li>
    {% endif %}
  {% endfor %}
  {{ block.super }}
{% endblock %}

{% block object-tools %}
  {{ block.super }}
  {% for tool in objectactions %}
    {% if tool.has_inline_form %}
        {% url tools_view_name pk=object_id tool=tool.name as action_url %}
        <div class="clear">
          <form name="{{ tool.name }}__form" method="post" action="{% add_preserved_filters action_url %}">
            {% csrf_token %}
            <ul class="object-tools django-object-actions">
              {{ tool.form.as_ul }}
              <li class="objectaction-item" data-tool-name="{{ tool.name }}">
                <a href="javascript:window.document.forms['{{ tool.name }}__form'].submit()" title="{{ tool.standard_attrs.title }}"
                  {% for k, v in tool.custom_attrs.items %}
                    {{ k }}="{{ v }}"
                  {% endfor %}
                  class="{{ tool.standard_attrs.class }}">
                  {{ tool.label|capfirst }}
                </a>
              </li>
            </ul>
          </form>
        </div>
    {% endif %}
  {% endfor %}
  <div class="clear"></div>
{% endblock %}
