kopia lustrzana https://github.com/wagtail/wagtail
Rename SubmissionsListView.ordering to default_ordering for consistency with BaseListingView
rodzic
9d7cc96847
commit
af80198c7d
|
@ -586,11 +586,13 @@ class FormPage(AbstractEmailForm):
|
|||
]
|
||||
```
|
||||
|
||||
(custom_form_submission_listing)=
|
||||
|
||||
## Customise form submissions listing in Wagtail Admin
|
||||
|
||||
The Admin listing of form submissions can be customized by setting the attribute `submissions_list_view_class` on your FormPage model.
|
||||
|
||||
The list view class must be a subclass of `SubmissionsListView` from `wagtail.contrib.forms.views`, which is a child class of Django's class based {class}`~django.views.generic.list.ListView`.
|
||||
The list view class must be a subclass of `SubmissionsListView` from `wagtail.contrib.forms.views`, which is a subclass of `wagtail.admin.views.generic.base.BaseListingView` and Django's class based {class}`~django.views.generic.list.ListView`.
|
||||
|
||||
Example:
|
||||
|
||||
|
@ -601,7 +603,7 @@ from wagtail.contrib.forms.views import SubmissionsListView
|
|||
|
||||
class CustomSubmissionsListView(SubmissionsListView):
|
||||
paginate_by = 50 # show more submissions per page, default is 20
|
||||
ordering = ('submit_time',) # order submissions by oldest first, normally newest first
|
||||
default_ordering = ('submit_time',) # order submissions by oldest first, normally newest first
|
||||
ordering_csv = ('-submit_time',) # order csv export by newest first, normally oldest first
|
||||
|
||||
# override the method to generate csv filename
|
||||
|
@ -627,6 +629,10 @@ class FormPage(AbstractEmailForm):
|
|||
# content_panels = ...
|
||||
```
|
||||
|
||||
```{versionchanged} 6.1
|
||||
The `SubmissionsListView` class is now a subclass of Wagtail's generic `BaseListingView`. As a result, the `ordering` attribute has been renamed to `default_ordering`.
|
||||
```
|
||||
|
||||
## Adding a custom field type
|
||||
|
||||
First, make the new field type available in the page editor by changing your `FormField` model.
|
||||
|
|
|
@ -92,6 +92,15 @@ depth: 1
|
|||
|
||||
## Upgrade considerations
|
||||
|
||||
## Upgrade considerations - changes affecting Wagtail customizations
|
||||
|
||||
### Changes to `SubmissionsListView` class
|
||||
|
||||
As part of the Universal Listings project, the `SubmissionsListView` for listing form submissions in the `wagtail.contrib.forms` app has been refactored to become a subclass of `wagtail.admin.views.generic.base.BaseListingView`. As a result, the class has undergone a number of changes, including the following:
|
||||
|
||||
- The filtering mechanism has been reimplemented to use django-filter.
|
||||
- The `ordering` attribute has been renamed to `default_ordering`.
|
||||
|
||||
## Upgrade considerations - changes to undocumented internals
|
||||
|
||||
### Deprecation of `window.chooserUrls` within Draftail choosers
|
||||
|
|
|
@ -158,7 +158,7 @@ class SubmissionsListView(SpreadsheetExportMixin, BaseListingView):
|
|||
template_name = "wagtailforms/submissions_index.html"
|
||||
context_object_name = "submissions"
|
||||
form_page = None
|
||||
ordering = ("-submit_time",)
|
||||
default_ordering = ("-submit_time",)
|
||||
ordering_csv = ("submit_time",) # keep legacy CSV ordering
|
||||
orderable_fields = (
|
||||
"id",
|
||||
|
@ -195,18 +195,6 @@ class SubmissionsListView(SpreadsheetExportMixin, BaseListingView):
|
|||
queryset = submission_class._default_manager.filter(page=self.form_page)
|
||||
return queryset
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = self.get_base_queryset()
|
||||
queryset = self.filter_queryset(queryset)
|
||||
|
||||
ordering = self.get_ordering()
|
||||
if ordering:
|
||||
if isinstance(ordering, str):
|
||||
ordering = (ordering,)
|
||||
queryset = queryset.order_by(*ordering)
|
||||
|
||||
return queryset
|
||||
|
||||
def get_validated_ordering(self):
|
||||
"""Return a dict of field names with ordering labels if ordering is valid"""
|
||||
orderable_fields = self.orderable_fields or ()
|
||||
|
@ -215,7 +203,7 @@ class SubmissionsListView(SpreadsheetExportMixin, BaseListingView):
|
|||
# Revert to CSV order_by submit_time ascending for backwards compatibility
|
||||
default_ordering = self.ordering_csv or ()
|
||||
else:
|
||||
default_ordering = self.ordering or ()
|
||||
default_ordering = self.default_ordering or ()
|
||||
if isinstance(default_ordering, str):
|
||||
default_ordering = (default_ordering,)
|
||||
ordering_strs = self.request.GET.getlist("order_by") or list(default_ordering)
|
||||
|
|
|
@ -51,7 +51,7 @@ def message_test(request):
|
|||
|
||||
class CustomSubmissionsListView(SubmissionsListView):
|
||||
paginate_by = 50
|
||||
ordering = ("submit_time",)
|
||||
default_ordering = ("submit_time",)
|
||||
ordering_csv = ("-submit_time",)
|
||||
|
||||
def get_csv_filename(self):
|
||||
|
|
Ładowanie…
Reference in New Issue