From 8d1b07427109b7421a6eda82c49debcfa44474ae Mon Sep 17 00:00:00 2001 From: Raffaele Salmaso Date: Thu, 22 Feb 2018 23:31:35 +0100 Subject: [PATCH] Update TextInputPrepend widget to template rendering. --- src/wiki/forms.py | 10 +++++----- src/wiki/templates/wiki/forms/text.html | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 src/wiki/templates/wiki/forms/text.html diff --git a/src/wiki/forms.py b/src/wiki/forms.py index 5d4b9c86..ee320437 100644 --- a/src/wiki/forms.py +++ b/src/wiki/forms.py @@ -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( - '
%s%s
' % - (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): diff --git a/src/wiki/templates/wiki/forms/text.html b/src/wiki/templates/wiki/forms/text.html new file mode 100644 index 00000000..23246aa8 --- /dev/null +++ b/src/wiki/templates/wiki/forms/text.html @@ -0,0 +1 @@ +
{{ prepend }}{% include "django/forms/widgets/input.html" %}
-- 2.45.2