Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
5f01c3ae
Commit
5f01c3ae
authored
Aug 27, 2015
by
Paul Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
editable list - change str to text_type and fix unicode string issue with json.dumps
parent
1f14a3e3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
widgets.py
flask_admin/model/widgets.py
+11
-9
No files found.
flask_admin/model/widgets.py
View file @
5f01c3ae
...
...
@@ -2,7 +2,7 @@ from flask import json
from
jinja2
import
escape
from
wtforms.widgets
import
HTMLString
,
html_params
from
flask_admin._compat
import
as_unicode
from
flask_admin._compat
import
as_unicode
,
text_type
from
flask_admin.babel
import
gettext
from
flask_admin.helpers
import
get_url
from
flask_admin.form
import
RenderTemplateWidget
...
...
@@ -114,12 +114,13 @@ class XEditableWidget(object):
elif
subfield
.
type
==
'Select2Field'
:
kwargs
[
'data-type'
]
=
'select'
choices
=
[{
'value'
:
x
,
'text'
:
y
}
for
x
,
y
in
subfield
.
choices
]
kwargs
[
'data-source'
]
=
choices
# prepend a blank field to choices if allow_blank = True
if
getattr
(
subfield
,
'allow_blank'
,
False
):
kwargs
[
'data-source'
]
.
insert
(
0
,
{
'value'
:
'__None'
,
'text'
:
''
})
choices
.
insert
(
0
,
{
'value'
:
'__None'
,
'text'
:
''
})
# json.dumps fixes issue with unicode strings not loading correctly
kwargs
[
'data-source'
]
=
json
.
dumps
(
choices
)
elif
subfield
.
type
==
'DateField'
:
kwargs
[
'data-type'
]
=
'combodate'
kwargs
[
'data-format'
]
=
'YYYY-MM-DD'
...
...
@@ -147,14 +148,15 @@ class XEditableWidget(object):
choices
=
[]
for
choice
in
subfield
:
try
:
choices
.
append
({
'value'
:
str
(
choice
.
_value
()),
'text'
:
str
(
choice
.
label
.
text
)})
choices
.
append
({
'value'
:
text_type
(
choice
.
_value
()),
'text'
:
text_type
(
choice
.
label
.
text
)})
except
TypeError
:
# unable to display text value
choices
.
append
({
'value'
:
str
(
choice
.
_value
()),
'text'
:
''
})
choices
.
append
({
'value'
:
text_type
(
choice
.
_value
()),
'text'
:
''
})
#
includes blank fiel
d if allow_blank
kwargs
[
'data-source'
]
=
choices
#
blank field is already include
d if allow_blank
kwargs
[
'data-source'
]
=
json
.
dumps
(
choices
)
else
:
raise
Exception
(
'Unsupported field type:
%
s'
%
(
type
(
subfield
),))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment