kopia lustrzana https://github.com/wagtail/wagtail
Rename export_heading_overrides to export_headings
rodzic
7ee943a9c0
commit
a1b09f65c9
|
@ -77,16 +77,16 @@ For our example, we might want to know when the page was last published, so we'l
|
|||
|
||||
``list_export = ReportView.list_export + ['last_published_at']``
|
||||
|
||||
.. attribute:: export_heading_overrides
|
||||
.. attribute:: export_headings
|
||||
|
||||
(dictionary)
|
||||
|
||||
A dictionary of any fields/attributes in ``list_export`` for which you wish to manually specify a heading for the spreadsheet
|
||||
column, and their headings. If unspecified, the heading will be taken from the field ``verbose_name`` if applicable, and the
|
||||
attribute string otherwise. For our example, ``last_published_at`` will automatically get a heading of ``"Last Published At"``,
|
||||
but a simple "Last Published" looks neater. We'll add that by setting ``export_heading_overrides``:
|
||||
but a simple "Last Published" looks neater. We'll add that by setting ``export_headings``:
|
||||
|
||||
``export_heading_overrides = dict(last_published_at='Last Published', **ReportView.export_heading_overrides)``
|
||||
``export_headings = dict(last_published_at='Last Published', **ReportView.export_headings)``
|
||||
|
||||
.. attribute:: custom_value_preprocess
|
||||
|
||||
|
@ -197,7 +197,7 @@ The full code
|
|||
title = "Pages with unpublished changes"
|
||||
|
||||
list_export = ReportView.list_export + ['last_published_at']
|
||||
export_heading_overrides = dict(last_published_at='Last Published', **ReportView.export_heading_overrides)
|
||||
export_headings = dict(last_published_at='Last Published', **ReportView.export_headings)
|
||||
|
||||
def get_queryset(self):
|
||||
return Page.objects.filter(has_unpublished_changes=True)
|
||||
|
|
|
@ -44,7 +44,7 @@ class SpreadsheetExportMixin:
|
|||
list: {FORMAT_CSV: list_to_str, FORMAT_XLSX: list_to_str},
|
||||
}
|
||||
# A dictionary of column heading overrides in the format {field: heading}
|
||||
export_heading_overrides = {}
|
||||
export_headings = {}
|
||||
|
||||
def get_filename(self):
|
||||
""" Gets the base filename for the exported spreadsheet, without extensions """
|
||||
|
@ -111,7 +111,7 @@ class SpreadsheetExportMixin:
|
|||
|
||||
def get_heading(self, queryset, field):
|
||||
""" Get the heading label for a given field for a spreadsheet generated from queryset """
|
||||
heading_override = self.export_heading_overrides.get(field)
|
||||
heading_override = self.export_headings.get(field)
|
||||
if heading_override:
|
||||
return force_str(heading_override)
|
||||
try:
|
||||
|
@ -186,7 +186,7 @@ class ReportView(SpreadsheetExportMixin, TemplateResponseMixin, BaseListView):
|
|||
template_name = "wagtailadmin/reports/base_report.html"
|
||||
title = ""
|
||||
paginate_by = 10
|
||||
export_heading_overrides = {
|
||||
export_headings = {
|
||||
"latest_revision_created_at": _("Updated"),
|
||||
"status_string": _("Status"),
|
||||
"content_type.model_class._meta.verbose_name.title": _("Type"),
|
||||
|
|
|
@ -155,7 +155,7 @@ class SubmissionsListView(SpreadsheetExportMixin, SafePaginateListView):
|
|||
data_fields = self.form_page.get_data_fields()
|
||||
# Set the export fields and the headings for spreadsheet export
|
||||
self.list_export = [field for field, label in data_fields]
|
||||
self.export_heading_overrides = dict(data_fields)
|
||||
self.export_headings = dict(data_fields)
|
||||
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
|
|
@ -267,7 +267,7 @@ class IndexView(SpreadsheetExportMixin, WMABaseView):
|
|||
|
||||
def get_heading(self, queryset, field):
|
||||
""" Get headings for exported spreadsheet column for the relevant field """
|
||||
heading_override = self.export_heading_overrides.get(field)
|
||||
heading_override = self.export_headings.get(field)
|
||||
if heading_override:
|
||||
return force_str(heading_override)
|
||||
return force_str(label_for_field(field, model=self.model).title())
|
||||
|
|
Ładowanie…
Reference in New Issue