<th>
{% if sort != key|add:"_asc" and sort != key|add:"_desc" %}
    <span onclick="sort2('{{ key }}_asc')">{{ name }}</span>
{% else %}
    {% if sort == key|add:"_asc" %}
    <span onclick="sort2('{{ key }}_desc')">
        {{ name }}<span class="glyphicon glyphicon-sort-by-attributes"></span>
    </span>
    {% else %}
    <span onclick="sort2('{{ key }}_asc')">
        {{ name }}<span class="glyphicon glyphicon-sort-by-attributes-alt"></span>
    </span>
    {% endif %}
{% endif %}
</th>
