Skip to content

How to limit targets in move page view #41

@barsch

Description

@barsch

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions