django-cms
django-cms copied to clipboard
add_plugin always adds plugins as 'last-child' of target (CMSPLugin.move too)
Problem Description
Using from cms.api import add_plugin while passing a position
parameter different from last-child
leads in unexpected results: The new plugin is appended to the end of the list of children of the target
plugin.
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 left
and 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.
This functionality is part of the CMS v4 milestone and a functioning example already exists,.
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.
Still an issue (writing this to prevent automatic closing).
@Aiky30 Can you add anything new here?
Also, will it be backported to 3.x?
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.
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.
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.
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.
This will now be closed due to inactivity, but feel free to reopen it.