kopia lustrzana https://github.com/wagtail/wagtail
Add the ability to export snippet listing via SnippetViewSet.list_export
rodzic
a2487fe6d9
commit
0a731b37f4
|
@ -16,7 +16,12 @@
|
||||||
{% fragment as base_action_locale %}{% if locale %}{% include 'wagtailadmin/shared/locale_selector.html' with theme="large" %}{% endif %}{% endfragment %}
|
{% 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_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 %}
|
{% 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 %}
|
||||||
|
|
||||||
<div class="nice-padding{% if filters %} filterable{% endif %}">
|
<div class="nice-padding{% if filters %} filterable{% endif %}">
|
||||||
<div id="listing-results" class="snippets">
|
<div id="listing-results" class="snippets">
|
||||||
|
|
|
@ -33,6 +33,7 @@ from wagtail.admin.views.generic.preview import (
|
||||||
PreviewOnEdit,
|
PreviewOnEdit,
|
||||||
PreviewRevision,
|
PreviewRevision,
|
||||||
)
|
)
|
||||||
|
from wagtail.admin.views.mixins import SpreadsheetExportMixin
|
||||||
from wagtail.admin.views.reports.base import ReportView
|
from wagtail.admin.views.reports.base import ReportView
|
||||||
from wagtail.admin.viewsets import viewsets
|
from wagtail.admin.viewsets import viewsets
|
||||||
from wagtail.admin.viewsets.model import ModelViewSet
|
from wagtail.admin.viewsets.model import ModelViewSet
|
||||||
|
@ -154,7 +155,11 @@ class SnippetTitleColumn(TitleColumn):
|
||||||
cell_template_name = "wagtailsnippets/snippets/tables/title_cell.html"
|
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"
|
view_name = "list"
|
||||||
index_results_url_name = None
|
index_results_url_name = None
|
||||||
delete_url_name = None
|
delete_url_name = None
|
||||||
|
@ -203,6 +208,13 @@ class IndexView(generic.IndexViewOptionalFeaturesMixin, generic.IndexView):
|
||||||
|
|
||||||
return context
|
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):
|
class CreateView(generic.CreateEditViewOptionalFeaturesMixin, generic.CreateView):
|
||||||
view_name = "create"
|
view_name = "create"
|
||||||
|
@ -657,6 +669,8 @@ class SnippetViewSet(ModelViewSet):
|
||||||
#: If ``filterset_class`` is set, this attribute will be ignored.
|
#: If ``filterset_class`` is set, this attribute will be ignored.
|
||||||
list_filter = None
|
list_filter = None
|
||||||
|
|
||||||
|
list_export = []
|
||||||
|
|
||||||
#: The number of items to display per page in the index view. Defaults to 20.
|
#: The number of items to display per page in the index view. Defaults to 20.
|
||||||
list_per_page = 20
|
list_per_page = 20
|
||||||
|
|
||||||
|
@ -852,6 +866,7 @@ class SnippetViewSet(ModelViewSet):
|
||||||
delete_url_name=self.get_url_name("delete"),
|
delete_url_name=self.get_url_name("delete"),
|
||||||
list_display=self.list_display,
|
list_display=self.list_display,
|
||||||
list_filter=self.list_filter,
|
list_filter=self.list_filter,
|
||||||
|
list_export=self.list_export,
|
||||||
paginate_by=self.list_per_page,
|
paginate_by=self.list_per_page,
|
||||||
default_ordering=self.ordering,
|
default_ordering=self.ordering,
|
||||||
search_fields=self.search_fields,
|
search_fields=self.search_fields,
|
||||||
|
@ -874,6 +889,7 @@ class SnippetViewSet(ModelViewSet):
|
||||||
delete_url_name=self.get_url_name("delete"),
|
delete_url_name=self.get_url_name("delete"),
|
||||||
list_display=self.list_display,
|
list_display=self.list_display,
|
||||||
list_filter=self.list_filter,
|
list_filter=self.list_filter,
|
||||||
|
list_export=self.list_export,
|
||||||
paginate_by=self.list_per_page,
|
paginate_by=self.list_per_page,
|
||||||
default_ordering=self.ordering,
|
default_ordering=self.ordering,
|
||||||
search_fields=self.search_fields,
|
search_fields=self.search_fields,
|
||||||
|
|
Ładowanie…
Reference in New Issue