divio/django-cms — Issue #1123: Inconsistent placeholder rendering (using translations with PlaceholderField)
Author: neo64bit
Created: 2011-12-23 10:53:04+00:00
State: open

When using a PlaceholderField the admin site renders plugins from all languages, while when using the render_placeholder template tag in a template, only the plugins in the current language get rendered.

My goal with this is to make models that use django-nani/hvad for translations able to use placeholders (in a nice way). As the idea of plugins is to be multilingual, we should have a way to display and edit only plugins in the currently selected language tab.

From my investigation the cms does it like so. When adding plugins through ajax, the current language is retrieved from the selected tab in cms/static/cms/js/plugin_editor.js:

```var language = $('input.language_button.selected').attr('name'); # line 11```
This is easily fixable in nani/hvad's tabs (i have a patch ready).

Displaying the plugins on the admin site is done with a widget in cms/forms/widgets.py. Unfortuantely, PlaceholderField uses a different widget (PlaceholderPluginEditorWidget) to render its plugins, that does not filter by language.
```plugin_list = ph.cmsplugin_set.filter(parent=None).order_by('position') # line 199```
Just by adding the language in the filter I was able to make a nani/hvad translated model with placeholders.
```plugin_list = ph.cmsplugin_set.filter(parent=None, language=language).order_by('position')```

Obviously, it is not a good idea to just change PlaceholderPluginEditorWidget, as it would not work for users that do not want translations on their placeholders. What do you think would be the best solution for this? Would it be possible to add a widget option to the PlaceholderField and implementing a new, language aware PlaceholderPluginEditorWidget which you would then just choose in case you want to use translated placeholders?

All feedback is welcome, if I got something wrong please say so. Thanks!