{% load permissions_widget_tags i18n %}

<table class="table permissions-widget">
    <thead>
        <tr>
            <th>{% trans 'App & Model' %}</th>
            {% for permission_type in default_permission_types %}
                <th>
                    {{ permission_type|translate|capfirst }}
                </th>
            {% endfor %}
            <th>
                {% trans 'Other' %}
            </th>
        </tr>
    </thead>
    <tbody>
        {% for row in table %}
            {% ifchanged row.app %}
                <tr>
                   <th colspan="{{ default_permission_types|length|add:"2" }}">
                        {{ row.app|translate|capfirst }}
                   </th>
                </tr>
            {% endifchanged %}

            {% ifchanged row.model %}
            <tr>
                <td>
                    {{ row.model|capfirst }}
                </td>
                {% for permission_type in default_permission_types %}
                    {% with row.permissions|get_item:permission_type as permission %}
                        <td {% if permission %}class="{{ permission_type }}"{% endif %}>
                            {% if permission %}
                                <input name="{{ name }}" title="{{ permission.name|translate|capfirst }}" {% if permission.pk in value %}checked="checked"{% endif %} value="{{ permission.pk }}" type="checkbox" />
                                {{ permission_type|translate|capfirst }}
                            {% endif %}
                        </td>
                    {% endwith %}
                {% endfor %}
                <td>
                    {% for permission_type in custom_permission_types %}
                        {% with row.permissions|get_item:permission_type as permission %}
                            {% if permission %}
                                <input name="{{ name }}" title="{{ permission.name|translate|capfirst }}" {% if permission.pk in value %}checked="checked"{% endif %} value="{{ permission.pk }}" type="checkbox" />
                                {{ permission.name|translate|capfirst }}
                                <br>
                            {% endif %}
                        {% endwith %}
                    {% endfor %}
                </td>
            </tr>
            {% endifchanged %}
        {% endfor %}
    </tbody>
</table>
