-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PageListingViewSet for custom per-page-type page listings #11485
Conversation
Manage this branch in SquashTest this branch here: https://gasmanfeaturepage-listing-view-rcsck.squash.io |
812fde1
to
76dc7fe
Compare
Rebased |
62b55b9
to
0f710fa
Compare
Re-rebased following #11483 :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and works well, thank you! One minor comment for a potential cleanup, but otherwise I think this just needs a rebase.
wagtail/admin/views/pages/listing.py
Outdated
columns = ( | ||
IndexView.columns[0:3] | ||
+ [ | ||
Column( | ||
"type", | ||
label=_("Type"), | ||
accessor="page_type_display_name", | ||
sort_key="content_type", | ||
width="12%", | ||
), | ||
] | ||
+ IndexView.columns[3:] | ||
+ [ | ||
NavigateToChildrenColumn("navigate", width="10%"), | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to use Django's @classproperty
here? e.g.
columns = ( | |
IndexView.columns[0:3] | |
+ [ | |
Column( | |
"type", | |
label=_("Type"), | |
accessor="page_type_display_name", | |
sort_key="content_type", | |
width="12%", | |
), | |
] | |
+ IndexView.columns[3:] | |
+ [ | |
NavigateToChildrenColumn("navigate", width="10%"), | |
] | |
) | |
@classproperty | |
def columns(cls): | |
columns = IndexView.columns.copy() | |
columns.insert( | |
3, | |
Column( | |
"type", | |
label=_("Type"), | |
accessor="page_type_display_name", | |
sort_key="content_type", | |
width="12%", | |
), | |
) | |
columns.append(NavigateToChildrenColumn("navigate", width="10%")) | |
return columns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Applied in 4340e21.
@cached_property | ||
def locale(self): | ||
return self.get_locale() | ||
|
||
@cached_property | ||
def translations(self): | ||
return self.get_translations() if self.locale else [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Been meaning to do this 😄
0f710fa
to
b9d86c0
Compare
Rebased - documentation still to come. |
Docs added - ready for re-review now. |
@@ -0,0 +1,64 @@ | |||
# Custom page listings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have a corresponding entry for PageListingViewSet
in https://github.com/wagtail/wagtail/blob/main/docs/reference/viewsets.md?plain=1, and reword one of the sentences here to explicitly mention PageListingViewSet
with a link to the section in the API reference?
With enough docstrings in the source code, this should be just autodoc directives for the most part (if not all).
Then, add an explicit target so we can link to this from the reference docs.
# Custom page listings | |
(custom_page_listings)= | |
# Custom page listings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @laymonage! Have added the reference docs in 2de9bd6.
wagtail/admin/viewsets/pages.py
Outdated
class PageListingViewSet(ViewSet): | ||
#: The view class to use for the index view; must be a subclass of ``wagtail.admin.views.pages.listing.IndexView``. | ||
index_view_class = IndexView | ||
model = Page | ||
columns = IndexView.columns | ||
filterset_class = IndexView.filterset_class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.g.
class PageListingViewSet(ViewSet): | |
#: The view class to use for the index view; must be a subclass of ``wagtail.admin.views.pages.listing.IndexView``. | |
index_view_class = IndexView | |
model = Page | |
columns = IndexView.columns | |
filterset_class = IndexView.filterset_class | |
class PageListingViewSet(ViewSet): | |
""" | |
A viewset to present a flat listing of all pages of a specific type. | |
All attributes and methods from :class:`~wagtail.admin.viewsets.base.ViewSet` | |
are available. | |
For more information on how to use this class, see :ref:`custom_page_listings`. | |
""" | |
#: The view class to use for the index view; must be a subclass of ``wagtail.admin.views.pages.listing.IndexView``. | |
index_view_class = IndexView | |
#: Required; the page model class that this viewset will work with. | |
model = Page | |
#: A list of ``wagtail.admin.ui.tables.Column`` instances for the columns in the listing. | |
columns = IndexView.columns | |
#: A subclass of ``wagtail.admin.filters.WagtailFilterSet``, which is a | |
#: subclass of `django_filters.FilterSet <https://django-filter.readthedocs.io/en/stable/ref/filterset.html>`_. | |
#: This will be passed to the ``filterset_class`` attribute of the index view. | |
filterset_class = IndexView.filterset_class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! As you said, the next step for ModelAdmin parity would be to add a ChooseParentView
-equivalent. I'll create a separate issue for this 😃
This avoids situations where the corresponding `get_*` functions cannot be evaluated during `setup()` because they depend on information received later (e.g. `parent_page` in the case of the page listing view)
Co-authored-by: sage <laymonage@gmail.com>
2de9bd6
to
c741351
Compare
Introduce a new PageListingViewSet to provide filterable, customisable flat listings of a given page type. These share most of the functionality of the new universal listing implementation for pages, except for the ability to navigate through the tree (which is now shifted into a separate
ExplorableIndexView
subclass), and can potentially serve as a replacement for ModelAdmin's page model support. (It is currently missing the functionality for adding a new page, possibly choosing a parent page along the way.)This can be tested against bakerydemo by adding the following to bakerydemo/base/wagtail_hooks.py:
Please check the following:
make lint
from the Wagtail root.Footnotes
Development Testing ↩