class AppendWidget(Widget): u""" Widget that append boostrap-style span with data to specified base widget """ def __init__(self, base_widget, data, *args, **kwargs): u"""Initialise widget and get base instance""" super(AppendWidget, self).__init__(*args, **kwargs) self.base_widget = base_widget(*args, **kwargs) self.data = data def render(self, name, value, attrs=None): u"""Render base widget and add bootstrap spans""" field = self.base_widget.render(name, value, attrs) return mark_safe(( u'
' u' %(field)s%(data)s' u'
' ) % {'field': field, 'data': self.data})