Improve page chooser (widgets.AdminChooser) when copying a page
msochel opened this issue · comments
Is your proposal related to a problem?
When a user is in the form to copy a page (CopyForm
), some pages appear as available destinations when in fact it is not a possible destination due to the hierarchy of the page to copy. Currently playing with the bakarydemo
project, I am copying a
location
type page and the widgets.AdminPageChooser
visually show and lets select other types of pages as possible destinations. At the end of the flow, it throws an error notification that may not be too clear.
Describe the solution you'd like
I would like the page chooser to gray out the page types that do not follow the hierarchy.
My suggestion is to pass the target_models
parameter to widgets.AdminPageChooser
on CopyForm, which allows us to specify the types of pages that can only be selectable. In this case, I would suggest passing as the value of this parameter the value returned by the function allowed_parent_page_models
self.fields["new_parent_page"] = forms.ModelChoiceField(
initial=self.page.get_parent(),
queryset=Page.objects.all(),
widget=widgets.AdminPageChooser(target_models=self.page.specific_class.allowed_parent_page_models(), can_choose_root=True, user_perms="copy_to"),
label=_("New parent page"),
help_text=_("This copy will be a child of this given parent page."),
)
Following the example on bakerydemo
and taking as reference the mentioned change, the page selector would look like this
Working on this
Anyone can contribute to this. View our contributing guidelines, add a comment to the issue once you’re ready to start.