Inconsistent placeholder rendering (using translations with PlaceholderField) #1123

Closed
alesdotio opened this Issue Dec 23, 2011 · 4 comments

Projects

None yet

4 participants

@alesdotio
Contributor

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!

@ojii
Collaborator
ojii commented Jun 26, 2012

Note to self: the issue here is to make PlaceholderField compatible with things such as django-hvad

@ojii
Collaborator
ojii commented Jun 26, 2012

Proposed solution:

Optional argument to PlaceholderField: language_aware. If True, it renders only the plugins in the active language (frontend) and only displays the plugins in the active language (admin). If False, the field completely ignores the language field on the plugin.

Probably also needs an argument that takes a function that detects the language (in admin, maybe also in frontend). Since we don't want to hardcode this to hvad.

Further, I remember @evildmp having a similar issue, would the proposed solution be usable for you?

@jscontrust

Is somebody working on this? It would be really great to have this feature...

@digi604
Member
digi604 commented Apr 9, 2013

fixed in develop

@digi604 digi604 closed this Apr 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment