make render method for ButtonPlugin reusable
@@ -122,6 +122,19 @@ class BootstrapButtonMixin(IconPluginMixin):
css = {'all': ['cascade/css/admin/bootstrap4-buttons.css', 'cascade/css/admin/iconplugin.css']}
js = ['admin/js/jquery.init.js', 'cascade/js/admin/buttonmixin.js']
+ def render(self, context, instance, placeholder):
+ self.super(BootstrapButtonMixin, self).render(context, instance, placeholder)
+ if 'icon_font_class' in context:
+ mini_template = '{0}<i class="{1} {2}" aria-hidden="true"></i>{3}'
+ icon_align = instance.glossary.get('icon_align')
+ if icon_align == 'icon-left':
+ context['icon_left'] = format_html(mini_template, '', context['icon_font_class'], 'cascade-icon-left',
+ ' ')
+ elif icon_align == 'icon-right':
+ context['icon_right'] = format_html(mini_template, ' ', context['icon_font_class'],
+ 'cascade-icon-right', '')
+ return context
+
class BootstrapButtonFormMixin(LinkFormMixin, IconFormMixin, ButtonFormMixin):
require_link = False
@@ -163,15 +176,4 @@ class BootstrapButtonPlugin(BootstrapButtonMixin, LinkPluginBase):
attributes.update(cls.DEFAULT_BUTTON_ATTRIBUTES)
return attributes
- def render(self, context, instance, placeholder):
- self.super(BootstrapButtonPlugin, self).render(context, instance, placeholder)
- if 'icon_font_class' in context:
- mini_template = '{0}<i class="{1} {2}" aria-hidden="true"></i>{3}'
- icon_align = instance.glossary.get('icon_align')
- if icon_align == 'icon-left':
- context['icon_left'] = format_html(mini_template, '', context['icon_font_class'], 'cascade-icon-left', ' ')
- elif icon_align == 'icon-right':
- context['icon_right'] = format_html(mini_template, ' ', context['icon_font_class'], 'cascade-icon-right', '')
- return context
-
plugin_pool.register_plugin(BootstrapButtonPlugin)
