django-cms icon indicating copy to clipboard operation
django-cms copied to clipboard

add_plugin always adds plugins as 'last-child' of target (CMSPLugin.move too)

Open moellering opened this issue 5 years ago • 5 comments

Problem Description

Using from cms.api import add_plugin while passing a positionparameter different from last-child leads in unexpected results: The new plugin is appended to the end of the list of children of the targetplugin.

Problematic Code

The try ... except block inside the CMSPlugin.move overwrites the position value, after the move method of MP_Node is called. The said block ignores the pos parameter and sets the position attribute as if the position last-child would have been passed.

Workaround

One could set the position attribute of the plugin manually after creating it. See #5986 for a workaround for the first-child option. For leftand right values of the pos parameter however, this might be more complicated since modifying the positions of the following siblings is required. For add_plugin this is already done by the function itself. So a workaround for the right position parameter would be:

new_plugin = add_plugin(
                placeholder,
                'SomePluginName',
                position='right',
                target=target_plugin,
                language=target_plugin.language)
            new_plugin.position = target_plugin.position+1
            new_plugin.save()

Outlook

The problem has already been carried around quite a while. See #6049 from 2017 which is still in progress.

I assume the particular problem in this issue should be quick fix. I'll try to provide a fix in a PR until the end of the month.

moellering avatar Dec 17 '19 12:12 moellering

This functionality is part of the CMS v4 milestone and a functioning example already exists,.

Aiky30 avatar Nov 13 '20 12:11 Aiky30

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 30 '22 05:06 stale[bot]

Still an issue (writing this to prevent automatic closing).

febsn avatar Jul 11 '22 14:07 febsn

@Aiky30 Can you add anything new here?

marksweb avatar Jul 14 '22 22:07 marksweb

Also, will it be backported to 3.x?

febsn avatar Jul 15 '22 07:07 febsn

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 13 '22 10:10 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 11 '23 21:01 stale[bot]

We can mark this for 3.11.2. @febsn , would you be interested in creating a PR? I think we can quickly proceed with that.

fsbraun avatar Jan 12 '23 07:01 fsbraun

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 12 '23 09:04 stale[bot]

This will now be closed due to inactivity, but feel free to reopen it.

stale[bot] avatar May 10 '23 10:05 stale[bot]