diff --git a/wagtail/wagtaildocs/templates/wagtaildocs/documents/confirm_delete.html b/wagtail/wagtaildocs/templates/wagtaildocs/documents/confirm_delete.html index 36aa8462f0..d8c9ccedd4 100644 --- a/wagtail/wagtaildocs/templates/wagtaildocs/documents/confirm_delete.html +++ b/wagtail/wagtaildocs/templates/wagtaildocs/documents/confirm_delete.html @@ -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" %}
+ + {% usage_count_enabled as uc_enabled %} + {% if uc_enabled %} +
+ {% blocktrans count usage_count=document.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %} +
+ {% endif %} +

{% trans "Are you sure you want to delete this document?" %}

{% csrf_token %} diff --git a/wagtail/wagtaildocs/tests/test_admin_views.py b/wagtail/wagtaildocs/tests/test_admin_views.py index 03bd5cd982..bea877994b 100644 --- a/wagtail/wagtaildocs/tests/test_admin_views.py +++ b/wagtail/wagtaildocs/tests/test_admin_views.py @@ -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): """ diff --git a/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/confirm_delete.html b/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/confirm_delete.html index 8543cb1080..80fe98459a 100644 --- a/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/confirm_delete.html +++ b/wagtail/wagtailsnippets/templates/wagtailsnippets/snippets/confirm_delete.html @@ -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" %}
+ {% usage_count_enabled as uc_enabled %} + {% if uc_enabled %} + + {% endif %} +

{% blocktrans with snippet_type_name=model_opts.verbose_name %}Are you sure you want to delete this {{ snippet_type_name }}?{% endblocktrans %}

{% csrf_token %} diff --git a/wagtail/wagtailsnippets/tests.py b/wagtail/wagtailsnippets/tests.py index d8374edafc..69fcf15bf7 100644 --- a/wagtail/wagtailsnippets/tests.py +++ b/wagtail/wagtailsnippets/tests.py @@ -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']