snapshot: Enable Delete All only with non-default snapshots

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2018-02-12 16:38:50 +05:30
parent fe17a8e541
commit 074ab4a736
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 9 additions and 5 deletions

View File

@ -40,11 +40,11 @@
<div class="col-xs-6 text-right"> <div class="col-xs-6 text-right">
<a title="{% trans 'Delete all the snapshots' %}" <a title="{% trans 'Delete all the snapshots' %}"
role="button" class="btn btn-danger" role="button" class="btn btn-danger"
{% if snapshots|length == 1 %} {% if not has_deletable_snapshots %}
disabled="disabled" disabled="disabled"
{% else %} {% else %}
href="{% url 'snapshot:delete-all' %}" href="{% url 'snapshot:delete-all' %}"
{% endif %}> {% endif %}>
{% trans 'Delete All' %} {% trans 'Delete All' %}
</a> </a>
</div> </div>

View File

@ -52,11 +52,15 @@ def index(request):
output = actions.superuser_run('snapshot', ['list']) output = actions.superuser_run('snapshot', ['list'])
snapshots = json.loads(output) snapshots = json.loads(output)
has_deletable_snapshots = any(
[snapshot for snapshot in snapshots[1:]
if not snapshot['is_default']])
return TemplateResponse(request, 'snapshot.html', { return TemplateResponse(request, 'snapshot.html', {
'title': snapshot_module.name, 'title': snapshot_module.name,
'description': snapshot_module.description, 'description': snapshot_module.description,
'snapshots': snapshots, 'snapshots': snapshots,
'has_deletable_snapshots': has_deletable_snapshots,
'form': form 'form': form
}) })