0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 09:33:54 +01:00

Show Usage info link on delete form for Documents and Snippets

This commit is contained in:
Kees Hink 2017-10-19 14:45:48 +01:00 committed by Karl Hobley
parent 454af89c17
commit 034b3a32a5
4 changed files with 31 additions and 2 deletions

View File

@ -1,11 +1,19 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% load wagtailadmin_tags i18n %}
{% block titletag %}{% blocktrans with title=document.title %}Delete {{ title }}{% endblocktrans %}{% endblock %}
{% block content %}
{% trans "Delete document" as del_str %}
{% include "wagtailadmin/shared/header.html" with title=del_str subtitle=document.title icon="doc-full-inverse" %}
<div class="nice-padding">
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
<div class="usagecount">
<a href="{{ document.usage_url }}">{% blocktrans count usage_count=document.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
{% endif %}
<p>{% trans "Are you sure you want to delete this document?" %}</p>
<form action="{% url 'wagtaildocs:delete' document.id %}" method="POST">
{% csrf_token %}

View File

@ -296,6 +296,13 @@ class TestDocumentDeleteView(TestCase, WagtailTestUtils):
# Document should be deleted
self.assertFalse(models.Document.objects.filter(id=self.document.id).exists())
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_link(self):
response = self.client.get(reverse('wagtaildocs:delete', args=(self.document.id,)))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtaildocs/documents/confirm_delete.html')
self.assertIn('Used 0 times', str(response.content))
class TestMultipleDocumentUploader(TestCase, WagtailTestUtils):
"""

View File

@ -1,11 +1,18 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% load wagtailadmin_tags i18n %}
{% block titletag %}{% blocktrans with snippet_type_name=model_opts.verbose_name %}Delete {{ snippet_type_name }} - {{ instance }}{% endblocktrans %}{% endblock %}
{% block content %}
{% trans "Delete" as delete_str %}
{% include "wagtailadmin/shared/header.html" with title=delete_str subtitle=instance icon="snippet" %}
<div class="nice-padding">
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
<div class="usagecount">
<a href="{{ instance.usage_url }}">{% blocktrans count usage_count=instance.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
{% endif %}
<p>{% blocktrans with snippet_type_name=model_opts.verbose_name %}Are you sure you want to delete this {{ snippet_type_name }}?{% endblocktrans %}</p>
<form action="{% url 'wagtailsnippets:delete' model_opts.app_label model_opts.model_name instance.id %}" method="POST">
{% csrf_token %}

View File

@ -352,6 +352,13 @@ class TestSnippetDelete(TestCase, WagtailTestUtils):
# Check that the page is gone
self.assertEqual(Advert.objects.filter(text='test_advert').count(), 0)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_link(self):
response = self.client.get(reverse('wagtailsnippets:delete', args=('tests', 'advert', self.test_snippet.id, )))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailsnippets/snippets/confirm_delete.html')
self.assertIn('Used 2 times', str(response.content))
class TestSnippetChooserPanel(TestCase, WagtailTestUtils):
fixtures = ['test.json']