{% extends "admin/index.html" %}
{% load i18n %}

{% block content %}
	{# Following 'div' is copied from upstream 'admin/index.html' (DRY -- but how, django?). #}
	{# Pseudo-Blocks via comments mark local changes/addons to ease occasional manual syncing with upstream. #}
	{# It *should* be in-sync with version of lowest upstream we support (as per debian/control). #}
	{# FUTURE: django 3.1 supports overwriting app_list.html, but this would still only be a tiny improvement. #}

	<div id="content-main">
		{% if app_list %}
			{% for app in app_list %}
				<div class="app-{{ app.app_label }} module">
					<table>
						<caption>
							<a href="{{ app.app_url }}" class="section" title="{% blocktrans with name=app.name %}Models in the {{ name }} application{% endblocktrans %}">{{ app.name }}</a>
						</caption>

						{# BLOCK 1: ADDON: Daemon Run Options && Setup #}
						{% if app.mbd %}
							<tr>
								<td colspan="4">
									<p>
										Consider using <em>setup</em> -- easier way to maintain, suitable for most configurations: <a href="{% url "setup" %}">Setup</a>
									</p>
									{% if mbd.daemon.is_alive %}
										<p>
											<em>Warning</em>: The daemon is <span class="mbd-success">powered on</span>!&nbsp;
											It is recommended to <em>power off</em> for extensive maintenance.
										</p>
									{% endif %}
								</td>
							</tr>
						{% endif %}
						{# END BLOCK 1 #}

						{% for model in app.models %}

							{# BLOCK 2: ADDON: Extra Sub Header && Setup #}
							{% if model.mbd %}
								{% if model.mbd.header %}
									<tr><td colspan="4"><h2><a href="/doc/admin.html#{{ model.mbd.header|lower }}" title="Jump to administrator manual">{{ model.mbd.header }}</a></h2></td></tr>
								{% endif %}
							{% endif %}
							{# END BLOCK 2 #}

							<tr class="model-{{ model.object_name|lower }}">
								{% if model.admin_url %}
									<th scope="row"><a href="{{ model.admin_url }}">{{ model.name }}</a></th>
								{% else %}
									<th scope="row">{{ model.name }}</th>
								{% endif %}

								{# BLOCK 3: ADDON: Extra info && wizards after model name #}
								{% if model.mbd %}
									<td>
										{% mbd_model_stats model.mbd.class_path as stats %}
										(<span title="Total instances"><b>{{ stats.total }}</b></span>
										{% if stats.active %}<span title="Active instances" class="{% mbd_cssmap 'model_status' 'Active' %}">&nbsp;<b>{{ stats.active }}</b></span>{% endif %}
										{% if stats.prepared %}<span title="Prepared instances" class="{% mbd_cssmap 'model_status' 'Prepared' %}">&nbsp;<b>{{ stats.prepared }}</b></span>{% endif %}
										{% if stats.removed %}<span title="Removed instances" class="{% mbd_cssmap 'model_status' 'Removed' %}">&nbsp;<b>{{ stats.removed }}</b></span>{% endif %})
									</td>
								{% endif %}
								{# END BLOCK 2 #}

								{% if model.add_url %}
									<td><a href="{{ model.add_url }}" class="addlink">{% trans 'Add' %}</a></td>
								{% else %}
									<td>&nbsp;</td>
								{% endif %}

								{% if model.admin_url %}
									{% if model.view_only %}
										<td><a href="{{ model.admin_url }}" class="viewlink">{% trans 'View' %}</a></td>
									{% else %}
										<td><a href="{{ model.admin_url }}" class="changelink">{% trans 'Change' %}</a></td>
									{% endif %}
								{% else %}
									<td>&nbsp;</td>
								{% endif %}
							</tr>
						{% endfor %}
					</table>
				</div>
			{% endfor %}
		{% else %}
			<p>{% trans "You don't have permission to view or edit anything." %}</p>
		{% endif %}
	</div>
{% endblock content %}
