-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
It would be nice to have a way to disallow certain targets in the move view - e.g. moving pages outside of a "Home" node or disallow moving pages before fixed pages (read: node stays always on top in menu).
I tried to monkey patch feincms3.admin.MoveForm.__generate_choices method and filter only for allowed pages but to no success.
I somehow got it working now by overwriting the feincms3.admin.MoveForm.clean() method - but that feels wrong and is not very user friendly as all the move targets are still shown in the admin UI:
class MyMoveForm(MoveForm):
def clean(self):
data = super().clean()
if not data.get("new_location"):
return data
if self.request.user.is_superuser:
return data
# don't allow to create a new root node
relative = data["relative"]
first_or_right = data["first_or_right"]
if not relative:
raise ValidationError("You do not have the permission to move this page here!")
elif first_or_right =='right' and not relative.parent:
raise ValidationError("You do not have the permission to move this page here!")
@admin.register(models.Page)
class PageAdmin(ContentEditor, TreeAdmin):
...
def move_view(self, request, obj):
return self.action_form_view(
request, obj, form_class=MyMoveForm, title=f"Move {obj}"
)
An option to disallow certain pages as move target or any idea how to tackle that in a smart way is very appreciated.
Metadata
Metadata
Assignees
Labels
No labels