Permalink
Browse files

admin filters PlaceholderField plugins if placeholder is language_aware

  • Loading branch information...
1 parent 1c9b7f1 commit 413ef22fa09c9a69002e28c92a5c756886e6f96a @bercab committed Aug 20, 2012
Showing with 9 additions and 3 deletions.
  1. +4 −1 cms/forms/widgets.py
  2. +5 −2 cms/models/fields.py
View
@@ -177,9 +177,10 @@ def render(self, name, value, attrs=None, choices=()):
class PlaceholderPluginEditorWidget(PluginEditor):
attrs = {}
- def __init__(self, request, filter_func):
+ def __init__(self, request, filter_func, language_aware=False):
self.request = request
self.filter_func = filter_func
+ self.language_aware = language_aware
def __deepcopy__(self, memo):
obj = copy.copy(self)
@@ -198,6 +199,8 @@ def render(self, name, value, attrs=None):
plugin_list = ph.cmsplugin_set.filter(parent=None).order_by('position')
plugin_list = self.filter_func(self.request, plugin_list)
language = get_language_from_request(self.request)
+ if self.language_aware:
+ plugin_list = plugin_list.filter(language=language)
copy_languages = []
if ph.actions.can_copy:
copy_languages = ph.actions.get_copy_languages(
View
@@ -9,11 +9,13 @@
class PlaceholderField(models.ForeignKey):
- def __init__(self, slotname, default_width=None, actions=PlaceholderNoAction, **kwargs):
+ def __init__(self, slotname, default_width=None, language_aware=False,
+ actions=PlaceholderNoAction, **kwargs):
validate_placeholder_name(slotname)
self.slotname = slotname
self.default_width = default_width
self.actions = actions()
+ self.language_aware = language_aware
kwargs.update({'null': True}) # always allow Null
super(PlaceholderField, self).__init__(Placeholder, **kwargs)
@@ -26,7 +28,8 @@ def formfield(self, **kwargs):
def formfield_for_admin(self, request, filter_func, **kwargs):
defaults = {'label': capfirst(self.verbose_name), 'help_text': self.help_text}
defaults.update(kwargs)
- widget = PlaceholderPluginEditorWidget(request, filter_func)
+ widget = PlaceholderPluginEditorWidget(request, filter_func,
+ language_aware=self.language_aware)
widget.choices = []
return PlaceholderFormField(required=False, widget=widget, **defaults)

0 comments on commit 413ef22

Please sign in to comment.