diff --git a/wagtail/snippets/templates/wagtailsnippets/snippets/index.html b/wagtail/snippets/templates/wagtailsnippets/snippets/index.html index 8b3c3a6c04..4b90b817df 100644 --- a/wagtail/snippets/templates/wagtailsnippets/snippets/index.html +++ b/wagtail/snippets/templates/wagtailsnippets/snippets/index.html @@ -16,7 +16,12 @@ {% fragment as base_action_locale %}{% if locale %}{% include 'wagtailadmin/shared/locale_selector.html' with theme="large" %}{% endif %}{% endfragment %} {% fragment as action_url_add_snippet %}{% if can_add_snippet %}{% url view.add_url_name %}{% if locale %}?locale={{ locale.language_code }}{% endif %}{% endif %}{% endfragment %} {% fragment as action_text_snippet %}{% blocktrans trimmed with snippet_type_name=model_opts.verbose_name %}Add {{ snippet_type_name }}{% endblocktrans %}{% endfragment %} - {% include 'wagtailadmin/shared/header.html' with breadcrumb=breadcrumb title=model_opts.verbose_name_plural|capfirst icon=header_icon search_url=search_url base_actions=base_action_locale action_url=action_url_add_snippet action_icon="plus" action_text=action_text_snippet %} + {% fragment as extra_actions %} + {% if view.list_export %} + {% include view.export_buttons_template_name %} + {% endif %} + {% endfragment %} + {% include 'wagtailadmin/shared/header.html' with breadcrumb=breadcrumb title=model_opts.verbose_name_plural|capfirst icon=header_icon search_url=search_url base_actions=base_action_locale action_url=action_url_add_snippet action_icon="plus" action_text=action_text_snippet extra_actions=extra_actions %}
diff --git a/wagtail/snippets/views/snippets.py b/wagtail/snippets/views/snippets.py index 7f597fbef1..2dbb2152c6 100644 --- a/wagtail/snippets/views/snippets.py +++ b/wagtail/snippets/views/snippets.py @@ -33,6 +33,7 @@ from wagtail.admin.views.generic.preview import ( PreviewOnEdit, PreviewRevision, ) +from wagtail.admin.views.mixins import SpreadsheetExportMixin from wagtail.admin.views.reports.base import ReportView from wagtail.admin.viewsets import viewsets from wagtail.admin.viewsets.model import ModelViewSet @@ -154,7 +155,11 @@ class SnippetTitleColumn(TitleColumn): cell_template_name = "wagtailsnippets/snippets/tables/title_cell.html" -class IndexView(generic.IndexViewOptionalFeaturesMixin, generic.IndexView): +class IndexView( + SpreadsheetExportMixin, + generic.IndexViewOptionalFeaturesMixin, + generic.IndexView, +): view_name = "list" index_results_url_name = None delete_url_name = None @@ -203,6 +208,13 @@ class IndexView(generic.IndexViewOptionalFeaturesMixin, generic.IndexView): return context + def render_to_response(self, context, **response_kwargs): + if self.is_export: + return self.as_spreadsheet( + context["object_list"], self.request.GET.get("export") + ) + return super().render_to_response(context, **response_kwargs) + class CreateView(generic.CreateEditViewOptionalFeaturesMixin, generic.CreateView): view_name = "create" @@ -657,6 +669,8 @@ class SnippetViewSet(ModelViewSet): #: If ``filterset_class`` is set, this attribute will be ignored. list_filter = None + list_export = [] + #: The number of items to display per page in the index view. Defaults to 20. list_per_page = 20 @@ -852,6 +866,7 @@ class SnippetViewSet(ModelViewSet): delete_url_name=self.get_url_name("delete"), list_display=self.list_display, list_filter=self.list_filter, + list_export=self.list_export, paginate_by=self.list_per_page, default_ordering=self.ordering, search_fields=self.search_fields, @@ -874,6 +889,7 @@ class SnippetViewSet(ModelViewSet): delete_url_name=self.get_url_name("delete"), list_display=self.list_display, list_filter=self.list_filter, + list_export=self.list_export, paginate_by=self.list_per_page, default_ordering=self.ordering, search_fields=self.search_fields,