Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treebeard error when copying/pasting plugin #4856

Closed
4 tasks done
czpython opened this issue Dec 15, 2015 · 5 comments
Closed
4 tasks done

Treebeard error when copying/pasting plugin #4856

czpython opened this issue Dec 15, 2015 · 5 comments
Assignees
Milestone

Comments

@czpython
Copy link
Contributor

All plugins have an internal treebeard field called numchild whose value should be how many direct children does the plugin have.

Given the structure below:

cms_plugin_copy_error

If I copy the nested Row 1 Column plugin and paste it under another plugin like the style plugin, the new plugin will have its numchild attribute set to 0, this means that this new plugin will raise an exception every time I try to add a new plugin to it.

Here's a screencast of the issue:

https://drive.google.com/file/d/0B9SwgyV0g1hSS3RLa0ptUEg5U3c/view

Progress:

@FinalAngel FinalAngel added this to the 3.2.x milestone Dec 16, 2015
@mkoistinen mkoistinen self-assigned this Dec 29, 2015
@czpython czpython assigned czpython and unassigned mkoistinen Dec 29, 2015
@czpython czpython modified the milestones: 3.1.5, 3.2.x, 3.2 Dec 29, 2015
czpython added a commit to czpython/django-cms that referenced this issue Dec 29, 2015
czpython added a commit to czpython/django-cms that referenced this issue Dec 29, 2015
czpython added a commit to czpython/django-cms that referenced this issue Dec 29, 2015
czpython added a commit that referenced this issue Dec 30, 2015
czpython added a commit to czpython/django-cms that referenced this issue Dec 30, 2015
czpython added a commit to czpython/django-cms that referenced this issue Dec 30, 2015
czpython added a commit that referenced this issue Dec 31, 2015
@jrief
Copy link
Contributor

jrief commented Jan 5, 2016

Today I ran into the same problem in CMS-3.2, when using the function cms.api.add_plugin.

Something I don't understand, if someone adds a plugin as child to an existing plugin, then target is not None and line 345 plugin_base = plugin_base.move(target, pos=position) triggers.

Wouldn't this be the right place to recalculate the numchild for the target plugin?

@czpython
Copy link
Contributor Author

czpython commented Jan 5, 2016

Hello,

The numchild value is calculated by treebeard automatically.
Can you post a gist of the code you're using to reproduce the problem?

@jrief
Copy link
Contributor

jrief commented Jan 5, 2016

Sure, the working code is here: https://github.com/jrief/djangocms-cascade/blob/master/cmsplugin_cascade/clipboard/admin.py#L109

I'll try to extract the fundamental parts:

clipboard = Placeholder.objects.get(slot='clipboard')
language = 'en'
plugin = plugin_pool.get_plugin('BootstrapRowPlugin')
data = {'glossary': {}, 'numchild': 7}
root_instance = add_plugin(clipboard, plugin, language, **data)

here root_instance.numchild is set to 0 despite of its initial value of 7. I could live with that, if adding children would correct the problem.

Now, if I add another instance to the current one, say

child_instance = add_plugin(clipboard, plugin, language, target=root_instance, **data)

then root_instance.numchild should be 1, but it remains 0.

@czpython
Copy link
Contributor Author

czpython commented Jan 6, 2016

@jrief which cms version are you using?
I've tested this on release/3.2.x and it's working correctly:

textplugincls = plugin_pool.get_plugin('TextPlugin')
textdata = {'body': 'hello there'}

styleplugincls = plugin_pool.get_plugin('StylePlugin')
styledata = {'label': 'root node'}

root_instance = add_plugin(placeholder, styleplugincls, 'en', **styledata)

In [14]: root_instance.numchild
Out[14]: 0

child_instance = add_plugin(placeholder, textplugincls, 'en', target=root_instance, **textdata)

In [17]: root_instance.numchild
Out[17]: 1

In [19]: CMSPlugin.objects.get(pk=root_instance.pk).numchild
Out[19]: 1

@czpython
Copy link
Contributor Author

czpython commented Jan 7, 2016

@jrief I'm closing this ticket now as the original bug has been fixed in both CMS 3.2.1 and 3.1.5.
Feel free to open a new ticket if you can reproduce the issue with cms.api.add_plugin

@czpython czpython closed this as completed Jan 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants