Remove WAGTAIL_USAGE_COUNT_ENABLED setting

pull/9304/head
Karl Hobley 2022-09-12 15:13:25 +00:00 zatwierdzone przez Matt Westcott
rodzic 212b2e19a6
commit b714a30bff
17 zmienionych plików z 31 dodań i 133 usunięć

Wyświetl plik

@ -332,7 +332,7 @@ Specifies the number of images per page shown on the main Images listing in the
WAGTAILIMAGES_USAGE_PAGE_SIZE = 20
```
Specifies the number of items per page shown when viewing an image's usage (see [`WAGTAIL_USAGE_COUNT_ENABLED`](wagtail_usage_count_enabled)).
Specifies the number of items per page shown when viewing an image's usage.
### `WAGTAILIMAGES_CHOOSER_PAGE_SIZE`
@ -663,28 +663,6 @@ TAG_LIMIT = 5
Limit the number of tags that can be added to (django-taggit) Tag model. Default setting is `None`, meaning no limit on tags.
(wagtail_usage_count_enabled)=
## Usage for images, documents and snippets
### `WAGTAIL_USAGE_COUNT_ENABLED`
```python
WAGTAIL_USAGE_COUNT_ENABLED = True
```
When enabled Wagtail shows where a particular image, document or snippet is being used on your site.
This is disabled by default because it generates a query which may run slowly on sites with large numbers of pages.
A link will appear on the edit page (in the rightmost column) showing you how many times the item is used.
Clicking this link takes you to the "Usage" page, which shows you where the snippet, document or image is used.
The link is also shown on the delete page, above the "Delete" button.
```{note}
The usage count only applies to direct (database) references. Using documents, images and snippets within StreamFields or rich text fields will not be taken into account.
```
## Static files
### `WAGTAILADMIN_STATIC_FILE_VERSION_STRINGS`

Wyświetl plik

@ -223,11 +223,6 @@ def hook_output(hook_name):
return mark_safe("".join(snippets))
@register.simple_tag
def usage_count_enabled():
return getattr(settings, "WAGTAIL_USAGE_COUNT_ENABLED", False)
@register.simple_tag
def base_url_setting(default=None):
return get_admin_base_url() or default

Wyświetl plik

@ -20,10 +20,7 @@
{% for document in items %}
<li>
<a href="{% url 'wagtaildocs:edit' document.item.id %}" target="_blank" rel="noreferrer">{{document.item.title}}</a>
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
(<a href="{{ document.item.usage_url }}">{% blocktrans trimmed count usage_count=document.item.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>)
{% endif %}
(<a href="{{ document.item.usage_url }}">{% blocktrans trimmed count usage_count=document.item.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>)
</li>
{% endfor %}
</ul>

Wyświetl plik

@ -6,13 +6,9 @@
{% 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 trimmed count usage_count=document.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
{% endif %}
<div class="usagecount">
<a href="{{ document.usage_url }}">{% blocktrans trimmed count usage_count=document.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
<p>
{# This message will only appear in the singular, but we specify a plural so it can share the translation string with confirm_bulk_delete.html #}

Wyświetl plik

@ -60,13 +60,10 @@
<dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd>
{% endif %}
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
<dt>{% trans "Usage" %}</dt>
<dd>
<a href="{{ document.usage_url }}">{% blocktrans trimmed count usage_count=document.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</dd>
{% endif %}
<dt>{% trans "Usage" %}</dt>
<dd>
<a href="{{ document.usage_url }}">{% blocktrans trimmed count usage_count=document.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</dd>
</dl>
</div>
</div>

Wyświetl plik

@ -544,7 +544,6 @@ class TestDocumentEditView(TestCase, WagtailTestUtils):
self.assertContains(response, "File not found")
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_link(self):
response = self.client.get(
reverse("wagtaildocs:edit", args=(self.document.id,))
@ -736,7 +735,6 @@ 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,))
@ -1737,12 +1735,10 @@ class TestUsageCount(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_unused_document_usage_count(self):
doc = models.Document.objects.get(id=1)
self.assertEqual(doc.get_usage().count(), 0)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_used_document_usage_count(self):
doc = models.Document.objects.get(id=1)
page = EventPage.objects.get(id=4)
@ -1752,17 +1748,6 @@ class TestUsageCount(TestCase, WagtailTestUtils):
event_page_related_link.save()
self.assertEqual(doc.get_usage().count(), 1)
def test_usage_count_does_not_appear(self):
doc = models.Document.objects.get(id=1)
page = EventPage.objects.get(id=4)
event_page_related_link = EventPageRelatedLink()
event_page_related_link.page = page
event_page_related_link.link_document = doc
event_page_related_link.save()
response = self.client.get(reverse("wagtaildocs:edit", args=(1,)))
self.assertNotContains(response, "Used 1 time")
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_count_appears(self):
doc = models.Document.objects.get(id=1)
page = EventPage.objects.get(id=4)
@ -1773,7 +1758,6 @@ class TestUsageCount(TestCase, WagtailTestUtils):
response = self.client.get(reverse("wagtaildocs:edit", args=(1,)))
self.assertContains(response, "Used 1 time")
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_count_zero_appears(self):
response = self.client.get(reverse("wagtaildocs:edit", args=(1,)))
self.assertContains(response, "Used 0 times")
@ -1785,16 +1769,10 @@ class TestGetUsage(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
def test_document_get_usage_not_enabled(self):
doc = models.Document.objects.get(id=1)
self.assertEqual(list(doc.get_usage()), [])
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_unused_document_get_usage(self):
doc = models.Document.objects.get(id=1)
self.assertEqual(list(doc.get_usage()), [])
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_used_document_get_usage(self):
doc = models.Document.objects.get(id=1)
page = EventPage.objects.get(id=4)
@ -1808,7 +1786,6 @@ class TestGetUsage(TestCase, WagtailTestUtils):
self.assertIsInstance(doc.get_usage()[0][1], list)
self.assertIsInstance(doc.get_usage()[0][1][0], ReferenceIndex)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_page(self):
doc = models.Document.objects.get(id=1)
page = EventPage.objects.get(id=4)
@ -1819,7 +1796,6 @@ class TestGetUsage(TestCase, WagtailTestUtils):
response = self.client.get(reverse("wagtaildocs:document_usage", args=(1,)))
self.assertContains(response, "Christmas")
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_page_no_usage(self):
response = self.client.get(reverse("wagtaildocs:document_usage", args=(1,)))
# There's no usage so there should be no table rows

Wyświetl plik

@ -1,6 +1,5 @@
from django.contrib.auth.models import Permission
from django.test import TestCase
from django.test.utils import override_settings
from django.urls import reverse
from wagtail.documents import get_document_model
@ -79,7 +78,6 @@ class TestDocumentBulkDeleteView(TestCase, WagtailTestUtils):
for document in self.documents:
self.assertFalse(Document.objects.filter(id=document.id).exists())
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_link(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)

Wyświetl plik

@ -17,13 +17,10 @@
{% endblocktrans %}
</p>
<ul>
{% usage_count_enabled as uc_enabled %}
{% for image in items %}
<li>
<a href="{% url 'wagtailimages:edit' image.item.id %}" target="_blank" rel="noreferrer">{{image.item.title}}</a>
{% if uc_enabled %}
(<a href="{{ image.item.usage_url }}">{% blocktrans trimmed count usage_count=image.item.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>)
{% endif %}
(<a href="{{ image.item.usage_url }}">{% blocktrans trimmed count usage_count=image.item.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>)
</li>
{% endfor %}
</ul>

Wyświetl plik

@ -11,12 +11,9 @@
{% image image max-800x600 %}
</div>
<div class="col6">
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
<div class="usagecount">
<a href="{{ image.usage_url }}">{% blocktrans trimmed count usage_count=image.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
{% endif %}
<div class="usagecount">
<a href="{{ image.usage_url }}">{% blocktrans trimmed count usage_count=image.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
<p>
{# This message will only appear in the singular, but we specify a plural so it can share the translation string with confirm_bulk_delete.html #}
{% blocktrans trimmed count counter=1 %}

Wyświetl plik

@ -91,13 +91,10 @@
<dt>{% trans "Filesize" %}</dt>
<dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd>
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
<dt>{% trans "Usage" %}</dt>
<dd>
<a href="{{ image.usage_url }}">{% blocktrans trimmed count usage_count=image.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</dd>
{% endif %}
<dt>{% trans "Usage" %}</dt>
<dd>
<a href="{{ image.usage_url }}">{% blocktrans trimmed count usage_count=image.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</dd>
</dl>
</div>
</div>

Wyświetl plik

@ -753,7 +753,6 @@ class TestImageEditView(TestCase, WagtailTestUtils):
response, f'<input type="hidden" value="{expected_next_url}" name="next">'
)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_with_usage_count(self):
response = self.get()
self.assertEqual(response.status_code, 200)
@ -1091,14 +1090,11 @@ class TestImageDeleteView(TestCase, WagtailTestUtils):
reverse("wagtailimages:delete", args=(self.image.id,)), post_data
)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=False)
def test_simple(self):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "wagtailimages/images/confirm_delete.html")
self.assertNotIn("Used ", str(response.content))
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_link(self):
response = self.get()
self.assertEqual(response.status_code, 200)

Wyświetl plik

@ -1,6 +1,5 @@
from django.contrib.auth.models import Permission
from django.test import TestCase
from django.test.utils import override_settings
from django.urls import reverse
from wagtail.images import get_image_model
@ -82,7 +81,6 @@ class TestImageBulkDeleteView(TestCase, WagtailTestUtils):
for image in self.images:
self.assertFalse(Image.objects.filter(id=image.id).exists())
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_link(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)

Wyświetl plik

@ -530,11 +530,9 @@ class TestUsageCount(TestCase):
file=get_test_image_file(),
)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_unused_image_usage_count(self):
self.assertEqual(self.image.get_usage().count(), 0)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_used_image_document_usage_count(self):
page = EventPage.objects.get(id=4)
event_page_carousel_item = EventPageCarouselItem()
@ -553,14 +551,9 @@ class TestGetUsage(TestCase):
file=get_test_image_file(),
)
def test_image_get_usage_not_enabled(self):
self.assertEqual(list(self.image.get_usage()), [])
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_unused_image_get_usage(self):
self.assertEqual(list(self.image.get_usage()), [])
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_used_image_document_get_usage(self):
page = EventPage.objects.get(id=4)
event_page_carousel_item = EventPageCarouselItem()

Wyświetl plik

@ -21,12 +21,9 @@
{% block items_with_access %}
{% if items %}
{% if items|length == 1 %}
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
<div class="usagecount">
<a href="{{ items.0.item.usage_url }}">{% blocktrans trimmed count usage_count=items.0.item.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
{% endif %}
<div class="usagecount">
<a href="{{ items.0.item.usage_url }}">{% blocktrans trimmed count usage_count=items.0.item.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
<p>{% blocktrans trimmed with snippet_type_name=model_opts.verbose_name %}Are you sure you want to delete this {{ snippet_type_name }}?{% endblocktrans %}</p>
{% else %}
<p>{% blocktrans trimmed with snippet_type_name=model_opts.verbose_name_plural count=items|length %}Are you sure you want to delete {{ count }} {{ snippet_type_name }}?{% endblocktrans %}</p>

Wyświetl plik

@ -17,12 +17,9 @@
<div class="nice-padding">
{% if objects|length == 1 %}
{% usage_count_enabled as uc_enabled %}
{% if uc_enabled %}
<div class="usagecount">
<a href="{{ objects.0.usage_url }}">{% blocktrans trimmed count usage_count=objects.0.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
{% endif %}
<div class="usagecount">
<a href="{{ objects.0.usage_url }}">{% blocktrans trimmed count usage_count=objects.0.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</div>
<p>{% blocktrans trimmed with snippet_type_name=model_opts.verbose_name %}Are you sure you want to delete this {{ snippet_type_name }}?{% endblocktrans %}</p>
{% else %}
<p>{% blocktrans trimmed with snippet_type_name=model_opts.verbose_name_plural count=objects|length %}Are you sure you want to delete {{ count }} {{ snippet_type_name }}?{% endblocktrans %}</p>

Wyświetl plik

@ -11,7 +11,6 @@
<div class="row row-flush">
{% usage_count_enabled as uc_enabled %}
<div class="{% if uc_enabled %}col10 divider-after{% else %}col12{% endif %}">
<form action="{{ action_url }}" method="POST" novalidate{% if form.is_multipart %} enctype="multipart/form-data"{% endif %} data-edit-form>
{% csrf_token %}
@ -32,19 +31,15 @@
</form>
</div>
{% if uc_enabled %}
<div class="col2 ">
<dl>
<dt>{% trans "Usage" %}</dt>
<dd>
<a href="{{ object.usage_url }}">{% blocktrans trimmed count usage_count=object.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</dd>
</dl>
</div>
{% endif %}
<div class="col2 ">
<dl>
<dt>{% trans "Usage" %}</dt>
<dd>
<a href="{{ object.usage_url }}">{% blocktrans trimmed count usage_count=object.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
</dd>
</dl>
</div>
</div>
{% endblock %}
{% block extra_css %}

Wyświetl plik

@ -2802,7 +2802,6 @@ 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):
management.call_command("rebuild_references_index")
@ -3050,7 +3049,6 @@ class TestUsageCount(TestCase):
super().setUpTestData()
management.call_command("rebuild_references_index")
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_snippet_usage_count(self):
advert = Advert.objects.get(pk=1)
self.assertEqual(advert.get_usage().count(), 2)
@ -3064,7 +3062,6 @@ class TestUsedBy(TestCase):
super().setUpTestData()
management.call_command("rebuild_references_index")
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_snippet_used_by(self):
advert = Advert.objects.get(pk=1)
@ -3074,7 +3071,6 @@ class TestUsedBy(TestCase):
self.assertIsInstance(advert.get_usage()[0][1][0], ReferenceIndex)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
class TestSnippetUsageView(TestCase, WagtailTestUtils):
def setUp(self):
self.user = self.login()
@ -4303,7 +4299,6 @@ class TestSnippetViewWithCustomPrimaryKey(TestCase, WagtailTestUtils):
response, "wagtailsnippets/snippets/confirm_delete.html"
)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_usage_link(self):
response = self.client.get(
reverse(
@ -4338,7 +4333,6 @@ class TestSnippetViewWithCustomPrimaryKey(TestCase, WagtailTestUtils):
status_code=301,
)
@override_settings(WAGTAIL_USAGE_COUNT_ENABLED=True)
def test_redirect_to_usage(self):
response = self.client.get(
"/admin/snippets/snippetstests/standardsnippetwithcustomprimarykey/snippet_2F01/usage/"