divio/django-cms — pull request #2518 by DylannCordel (2014-01-25 16:15:31+00:00)
Title: Add default children for default_plugins of placeholders

#2516

With this diff, we can now add children plugins for default plugins configured in placeholders in settings.py.
Here an exemple of settings.py :

```python
from djangocms_text_ckeditor.utils import plugin_to_tag

def upd_textplugin_ctn_with_child_link(plugin, request, conf):
textplugin = plugin.parent
needle = '%%(_tag_%s_%d)s' % (plugin.plugin_type, plugin.position)
if needle in textplugin.body:
textplugin.body = textplugin.body.replace(needle, plugin_to_tag(plugin))
textplugin.save()

CMS_PLACEHOLDER_CONF = {
'main_content': {
'name': _(u"Contenu principal"),
'plugins': ['TextPlugin', 'LinkPlugin'],
'default_plugins':[
{
'plugin_type':'TextPlugin',
'values':{
'body':'

Great websites : %(_tag_LinkPlugin_2)s and %(_tag_LinkPlugin_3)s

'
},
'children':[
{
'plugin_type':'LinkPlugin',
'values':{
'name':'django',
'url':'https://www.djangoproject.com/'
},
'post_add_process':upd_textplugin_ctn_with_child_link,
},
{
'plugin_type':'LinkPlugin',
'values':{
'name':'django-cms',
'url':'https://www.django-cms.org'
},
'post_add_process':upd_textplugin_ctn_with_child_link,
# If using LinkPlugin from djangocms-link which
# accepts children, you could add some grandchildren :
# 'children' : [
# ...
# ]
},
]
},
],
},
}
```

The "post_add_process" is required for some special plugins as textEditor because we have to reference children inside the parent's content. But for a simple plugin (LinkPlugin from djangocms-link), it's not necessary.
An other usefull usage of "post_add_process" is to easy add contextual default content. (with the current user, current page, current lang etc.)