You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The addition of PageListingViewSet in #11485 brings a flat-listing of pages of the same type, a feature similar to how ModelAdmin supports Page models. However, it currently lacks the option to create a new page of that type from the flat listing, as that needs a way to select the parent page for the new page. ModelAdmin handles this by having an intermediary ChooseParentView that gives you a form with only one field: the parent page where you want to create the new page under. It then redirects you to the create page view under that parent page with the correct page type already selected.
It would be nice to have something similar for PageListingViewSet as well.
Describe the solution you'd like
Create a view with a minimal form for choosing the parent page. Add it to the PageListingViewSet, and make it so that the index view links to that new view via the "add" button in the header.
See the ModelAdmin's ChooseParentView implementation for reference:
(I don't think we need the template to be customisable, so get_template_names don't need to be implemented.)
We may need the PagePermissionHelper.get_valid_parent_pages() logic to be implemented either in the view or possibly in the PagePermissionPolicy directly:
Perhaps it's a better idea to implement it in the view, so we can use PagePermissionTester.can_add_subpage(). Using that method in the PagePermissionPolicy is against the plan we have for wagtail/rfcs#92.
Describe alternatives you've considered
Maybe create a subclass of the page CreateView and incorporate the parent page chooser into the create view's form, but I reckon this will introduce more complexity as the page CreateView has always assumed the parent page is already pre-selected.
Additional context
Be aware of wagtail-nest/wagtail-modeladmin#19. We'll likely need to optimise the "valid parent pages" logic to avoid the same issue, so don't take the ModelAdmin implementation as-is.
Working on this
Anyone can contribute to this. Before working on this, I strongly recommend familiarising yourself with:
how ModelAdmin's support for pages works,
Wagtail's ViewSet mechanism
see example usages of ModelViewSet and SnippetViewSet for more details
I'll try to give this one a go, I started with creating a custom header template for PageListingViewSet index view that just adds the plus icon. I'll work on the ChooseParentView and the other stuff now. Any more tips on working on this would be really helpful.
Hey @laymonage, I added the base functionality in abdlrhman08/wagtail@4223cd6, for now I am using the modeladmins get_valid_parents implementaion. I am currently stuck on optimizing get_valid_parents and trying to figure it out. Your help would be greatly appreciated on this issue !
Is your proposal related to a problem?
The addition of
PageListingViewSet
in #11485 brings a flat-listing of pages of the same type, a feature similar to how ModelAdmin supports Page models. However, it currently lacks the option to create a new page of that type from the flat listing, as that needs a way to select the parent page for the new page. ModelAdmin handles this by having an intermediaryChooseParentView
that gives you a form with only one field: the parent page where you want to create the new page under. It then redirects you to the create page view under that parent page with the correct page type already selected.It would be nice to have something similar for
PageListingViewSet
as well.Describe the solution you'd like
Create a view with a minimal form for choosing the parent page. Add it to the
PageListingViewSet
, and make it so that the index view links to that new view via the "add" button in the header.See the ModelAdmin's
ChooseParentView
implementation for reference:https://github.com/wagtail-nest/wagtail-modeladmin/blob/742fbe8d5e942ba641af4c25fb181c65ad4858ed/wagtail_modeladmin/views.py#L926-L963
(I don't think we need the template to be customisable, so
get_template_names
don't need to be implemented.)We may need the
PagePermissionHelper.get_valid_parent_pages()
logic to be implemented either in the view or possibly in thePagePermissionPolicy
directly:https://github.com/wagtail-nest/wagtail-modeladmin/blob/742fbe8d5e942ba641af4c25fb181c65ad4858ed/wagtail_modeladmin/helpers/permission.py#L114-L153
Perhaps it's a better idea to implement it in the view, so we can use
PagePermissionTester.can_add_subpage()
. Using that method in thePagePermissionPolicy
is against the plan we have for wagtail/rfcs#92.Describe alternatives you've considered
Maybe create a subclass of the page
CreateView
and incorporate the parent page chooser into the create view's form, but I reckon this will introduce more complexity as the pageCreateView
has always assumed the parent page is already pre-selected.Additional context
Be aware of wagtail-nest/wagtail-modeladmin#19. We'll likely need to optimise the "valid parent pages" logic to avoid the same issue, so don't take the ModelAdmin implementation as-is.
Working on this
Anyone can contribute to this. Before working on this, I strongly recommend familiarising yourself with:
ViewSet
mechanismModelViewSet
andSnippetViewSet
for more detailsView our contributing guidelines, add a comment to the issue once you’re ready to start.
The text was updated successfully, but these errors were encountered: