Skip to content

Commit

Permalink
Merge pull request #1779 from alanhamlett/master
Browse files Browse the repository at this point in the history
use Markupsafe to support WTForms 3
  • Loading branch information
alanhamlett authored Dec 18, 2018
2 parents 829c24d + c4715f0 commit 1939762
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
5 changes: 5 additions & 0 deletions flask_admin/_backwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import sys
import warnings

try:
from wtforms.widgets import HTMLString as Markup
except ImportError:
from markupsafe import Markup # noqa: F401


def get_property(obj, name, old_name, default=None):
"""
Expand Down
22 changes: 12 additions & 10 deletions flask_admin/contrib/mongoengine/widgets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from wtforms.widgets import HTMLString, html_params
from wtforms.widgets import html_params

from jinja2 import escape

from mongoengine.fields import GridFSProxy, ImageGridFsProxy

from flask_admin._backwards import Markup
from flask_admin.helpers import get_url
from . import helpers

Expand Down Expand Up @@ -31,10 +32,10 @@ def __call__(self, field, **kwargs):
'marker': '_%s-delete' % field.name
}

return HTMLString('%s<input %s>' % (placeholder,
html_params(name=field.name,
type='file',
**kwargs)))
return Markup('%s<input %s>' % (placeholder,
html_params(name=field.name,
type='file',
**kwargs)))


class MongoImageInput(object):
Expand All @@ -46,7 +47,8 @@ class MongoImageInput(object):
' <input type="checkbox" name="%(marker)s">Delete</input>'
'</div>')

def __call__(self, field, **kwargs):

def __call__(self, field, **kwargs):
kwargs.setdefault('id', field.id)

placeholder = ''
Expand All @@ -57,7 +59,7 @@ def __call__(self, field, **kwargs):
'marker': '_%s-delete' % field.name
}

return HTMLString('%s<input %s>' % (placeholder,
html_params(name=field.name,
type='file',
**kwargs)))
return Markup('%s<input %s>' % (placeholder,
html_params(name=field.name,
type='file',
**kwargs)))
6 changes: 4 additions & 2 deletions flask_admin/contrib/sqla/widgets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from wtforms.widgets.core import HTMLString, escape
from wtforms.widgets.core import escape

from flask_admin._backwards import Markup


class CheckboxListInput:
Expand Down Expand Up @@ -26,4 +28,4 @@ def __call__(self, field, **kwargs):
'selected': ' checked' if selected else '',
}
items.append(self.template % args)
return HTMLString(''.join(items))
return Markup(''.join(items))
7 changes: 4 additions & 3 deletions flask_admin/form/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from werkzeug.datastructures import FileStorage

from wtforms import ValidationError, fields
from wtforms.widgets import HTMLString, html_params
from wtforms.widgets import html_params

try:
from wtforms.fields.core import _unset_value as unset_value
Expand All @@ -15,6 +15,7 @@
from flask_admin.babel import gettext
from flask_admin.helpers import get_url

from flask_admin._backwards import Markup
from flask_admin._compat import string_types, urljoin


Expand Down Expand Up @@ -59,7 +60,7 @@ def __call__(self, field, **kwargs):
else:
value = field.data or ''

return HTMLString(template % {
return Markup(template % {
'text': html_params(type='text',
readonly='readonly',
value=value,
Expand Down Expand Up @@ -108,7 +109,7 @@ def __call__(self, field, **kwargs):
else:
template = self.empty_template

return HTMLString(template % args)
return Markup(template % args)

def get_url(self, field):
if field.thumbnail_size:
Expand Down
7 changes: 4 additions & 3 deletions flask_admin/model/widgets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from flask import json
from jinja2 import escape
from wtforms.widgets import HTMLString, html_params
from wtforms.widgets import html_params

from flask_admin._backwards import Markup
from flask_admin._compat import as_unicode, text_type
from flask_admin.babel import gettext
from flask_admin.helpers import get_url
Expand Down Expand Up @@ -64,7 +65,7 @@ def __call__(self, field, **kwargs):
minimum_input_length = int(field.loader.options.get('minimum_input_length', 1))
kwargs.setdefault('data-minimum-input-length', minimum_input_length)

return HTMLString('<input %s>' % html_params(name=field.name, **kwargs))
return Markup('<input %s>' % html_params(name=field.name, **kwargs))


class XEditableWidget(object):
Expand Down Expand Up @@ -93,7 +94,7 @@ def __call__(self, field, **kwargs):

kwargs = self.get_kwargs(field, kwargs)

return HTMLString(
return Markup(
'<a %s>%s</a>' % (html_params(**kwargs),
escape(display_value))
)
Expand Down

0 comments on commit 1939762

Please sign in to comment.