Convert the TextAreaDiv widget to use template-based rendering as per Django's release notes: https://docs.djangoproject.com/en/2.0/releases/1.11/#template-based-widget-rendering

Signed-off-by: Michael Price <loneviking72@gmail.com>
This commit is contained in:
Michael Price
2018-03-02 02:37:22 -04:00
committed by Roberto Rosario
parent 2b77da369d
commit b1080e5fe5
2 changed files with 4 additions and 9 deletions

View File

@@ -0,0 +1,3 @@
<pre name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
{% if widget.value %}{{ widget.value }}{% endif %}</pre>

View File

@@ -109,6 +109,7 @@ class TextAreaDiv(forms.widgets.Widget):
Class to define a form widget that simulates the behavior of a
Textarea widget but using a div tag instead
"""
template_name = 'appearance/forms/widgets/textareadiv.html'
def __init__(self, attrs=None):
# The 'rows' and 'cols' attributes are required for HTML correctness.
@@ -117,15 +118,6 @@ class TextAreaDiv(forms.widgets.Widget):
default_attrs.update(attrs)
super(TextAreaDiv, self).__init__(default_attrs)
def render(self, name, value, attrs=None):
if value is None:
value = ''
flat_attrs = flatatt(self.build_attrs(attrs, name=name))
content = conditional_escape(force_text(value))
result = '<pre%s>%s</pre>' % (flat_attrs, content)
return mark_safe(result)
def two_state_template(state, ok_icon='fa fa-check', fail_icon='fa fa-times'):
if state: