diff --git a/wagtail/admin/views/generic/models.py b/wagtail/admin/views/generic/models.py index 59e638a1bc..e12f4fe258 100644 --- a/wagtail/admin/views/generic/models.py +++ b/wagtail/admin/views/generic/models.py @@ -252,7 +252,7 @@ class IndexView( def get_edit_url(self, instance): if self.edit_url_name: - return reverse(self.edit_url_name, args=(instance.pk,)) + return reverse(self.edit_url_name, args=(quote(instance.pk),)) def get_add_url(self): if self.add_url_name: diff --git a/wagtail/snippets/templates/wagtailsnippets/snippets/list.html b/wagtail/snippets/templates/wagtailsnippets/snippets/list.html index 6fe1d60567..4a11903ee3 100644 --- a/wagtail/snippets/templates/wagtailsnippets/snippets/list.html +++ b/wagtail/snippets/templates/wagtailsnippets/snippets/list.html @@ -1,24 +1,2 @@ -{% load i18n l10n wagtailadmin_tags wagtailsnippets_admin_tags %} -
{% trans "Title" %} | -
---|
-
-
|
-
{% blocktrans trimmed with snippet_type_name_plural=model_opts.verbose_name_plural %}Sorry, no {{ snippet_type_name_plural }} match your query{% endblocktrans %}
diff --git a/wagtail/snippets/templates/wagtailsnippets/snippets/type_index.html b/wagtail/snippets/templates/wagtailsnippets/snippets/type_index.html index a17261ea91..278d2f9def 100644 --- a/wagtail/snippets/templates/wagtailsnippets/snippets/type_index.html +++ b/wagtail/snippets/templates/wagtailsnippets/snippets/type_index.html @@ -64,6 +64,6 @@ {% include "wagtailadmin/shared/filters.html" %} {% endif %} {% trans "Select all snippets in listing" as select_all_text %} - {% include 'wagtailadmin/bulk_actions/footer.html' with select_all_obj_text=select_all_text app_label=model_opts.app_label model_name=model_opts.model_name objects=items %} + {% include 'wagtailadmin/bulk_actions/footer.html' with select_all_obj_text=select_all_text app_label=model_opts.app_label model_name=model_opts.model_name objects=page_obj %} {% endblock %} diff --git a/wagtail/snippets/tests/test_snippets.py b/wagtail/snippets/tests/test_snippets.py index 67bf118c43..b00702dfb4 100644 --- a/wagtail/snippets/tests/test_snippets.py +++ b/wagtail/snippets/tests/test_snippets.py @@ -127,7 +127,7 @@ class TestSnippetListView(TestCase, WagtailTestUtils): Advert.objects.create(pk=i, text="advert %d" % i) response = self.get() self.assertEqual(response.status_code, 200) - self.assertEqual(response.context["items"][0].text, "advert 10") + self.assertEqual(response.context["page_obj"][0].text, "advert 10") def test_simple_pagination(self): @@ -294,7 +294,7 @@ class TestModelOrdering(TestCase, WagtailTestUtils): reverse("wagtailsnippets_tests_advertwithtabbedinterface:list") ) self.assertEqual(response.status_code, 200) - self.assertEqual(response.context["items"][0].text, "aaaadvert") + self.assertEqual(response.context["page_obj"][0].text, "aaaadvert") def test_chooser_respects_model_ordering(self): response = self.client.get( @@ -325,7 +325,7 @@ class TestSnippetListViewWithSearchableSnippet(TestCase, WagtailTestUtils): self.assertTemplateUsed(response, "wagtailsnippets/snippets/type_index.html") # All snippets should be in items - items = list(response.context["items"].object_list) + items = list(response.context["page_obj"].object_list) self.assertIn(self.snippet_a, items) self.assertIn(self.snippet_b, items) self.assertIn(self.snippet_c, items) @@ -337,7 +337,7 @@ class TestSnippetListViewWithSearchableSnippet(TestCase, WagtailTestUtils): response = self.get({"q": "Hello"}) # Just snippets with "Hello" should be in items - items = list(response.context["items"].object_list) + items = list(response.context["page_obj"].object_list) self.assertIn(self.snippet_a, items) self.assertNotIn(self.snippet_b, items) self.assertIn(self.snippet_c, items) @@ -346,7 +346,7 @@ class TestSnippetListViewWithSearchableSnippet(TestCase, WagtailTestUtils): response = self.get({"q": "World"}) # Just snippets with "World" should be in items - items = list(response.context["items"].object_list) + items = list(response.context["page_obj"].object_list) self.assertNotIn(self.snippet_a, items) self.assertIn(self.snippet_b, items) self.assertIn(self.snippet_c, items) @@ -2861,7 +2861,7 @@ class TestSnippetListViewWithCustomPrimaryKey(TestCase, WagtailTestUtils): self.assertTemplateUsed(response, "wagtailsnippets/snippets/type_index.html") # All snippets should be in items - items = list(response.context["items"].object_list) + items = list(response.context["page_obj"].object_list) self.assertIn(self.snippet_a, items) self.assertIn(self.snippet_b, items) self.assertIn(self.snippet_c, items) diff --git a/wagtail/snippets/views/snippets.py b/wagtail/snippets/views/snippets.py index 042e9f6b33..70db4b28fe 100644 --- a/wagtail/snippets/views/snippets.py +++ b/wagtail/snippets/views/snippets.py @@ -18,7 +18,13 @@ from django.views.generic import TemplateView from wagtail.admin import messages from wagtail.admin.filters import DateRangePickerWidget, WagtailFilterSet from wagtail.admin.panels import get_edit_handler -from wagtail.admin.ui.tables import Column, DateColumn, InlineActionsTable, UserColumn +from wagtail.admin.ui.tables import ( + BulkActionsCheckboxColumn, + Column, + DateColumn, + InlineActionsTable, + UserColumn, +) from wagtail.admin.views.generic import CreateView, DeleteView, EditView, IndexView from wagtail.admin.views.generic.mixins import RevisionsRevertMixin from wagtail.admin.views.generic.models import RevisionsCompareView @@ -107,17 +113,18 @@ class List(IndexView): # If true, returns just the 'results' include, for use in AJAX responses from search results_only = False + def get_columns(self): + return [ + BulkActionsCheckboxColumn("checkbox", accessor=lambda obj: obj), + *super().get_columns(), + ] + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - # The shared admin templates expect the items to be a page object rather - # than the queryset (object_list), so we can't use context_object_name = "items". - paginated_items = context.get("page_obj") - context.update( { "model_opts": self.model._meta, - "items": paginated_items, "can_add_snippet": self.permission_policy.user_has_permission( self.request.user, "add" ),