~netlandish/django-wiki

8d1b07427109b7421a6eda82c49debcfa44474ae — Raffaele Salmaso 6 years ago 6eaf6e1
Update TextInputPrepend widget to template rendering.
2 files changed, 6 insertions(+), 5 deletions(-)

M src/wiki/forms.py
A src/wiki/templates/wiki/forms/text.html
M src/wiki/forms.py => src/wiki/forms.py +5 -5
@@ 354,16 354,16 @@ class SelectWidgetBootstrap(BuildAttrsCompat, forms.Select):


class TextInputPrepend(forms.TextInput):
    template_name = "wiki/forms/text.html"

    def __init__(self, *args, **kwargs):
        self.prepend = kwargs.pop('prepend', "")
        super().__init__(*args, **kwargs)

    def render(self, *args, **kwargs):
        html = super().render(*args, **kwargs)
        return mark_safe(
            '<div class="input-group"><span class="input-group-addon">%s</span>%s</div>' %
            (self.prepend, html))
    def get_context(self, name, value, attrs):
        context = super().get_context(name, value, attrs)
        context['prepend'] = mark_safe(self.prepend)
        return context


class CreateForm(forms.Form, SpamProtectionMixin):

A src/wiki/templates/wiki/forms/text.html => src/wiki/templates/wiki/forms/text.html +1 -0
@@ 0,0 1,1 @@
<div class="input-group"><span class="input-group-addon">{{ prepend }}</span>{% include "django/forms/widgets/input.html" %}</div>