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
97ec7f7c
Commit
97ec7f7c
authored
Sep 14, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #161. Support flat choices with MongoEngine backend
parent
9c503bc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
form.py
flask_admin/contrib/mongoengine/form.py
+8
-1
test_basic.py
flask_admin/tests/mongoengine/test_basic.py
+13
-0
No files found.
flask_admin/contrib/mongoengine/form.py
View file @
97ec7f7c
...
...
@@ -44,6 +44,13 @@ class CustomModelConverter(orm.ModelConverter):
return
p
def
_convert_choices
(
self
,
choices
):
for
c
in
choices
:
if
isinstance
(
c
,
tuple
):
yield
c
else
:
yield
(
c
,
c
)
def
clone_converter
(
self
,
view
):
return
self
.
__class__
(
view
)
...
...
@@ -71,7 +78,7 @@ class CustomModelConverter(orm.ModelConverter):
ftype
=
type
(
field
)
.
__name__
if
field
.
choices
:
kwargs
[
'choices'
]
=
field
.
choices
kwargs
[
'choices'
]
=
list
(
self
.
_convert_choices
(
field
.
choices
))
if
ftype
in
self
.
converters
:
kwargs
[
"coerce"
]
=
self
.
coerce
(
ftype
)
...
...
flask_admin/tests/mongoengine/test_basic.py
View file @
97ec7f7c
...
...
@@ -461,3 +461,16 @@ def test_nested_ajax_refs():
form
=
view1
.
create_form
()
eq_
(
type
(
form
.
nested
.
form
.
comment
)
.
__name__
,
'AjaxSelectField'
)
ok_
(
'nested-comment'
in
view1
.
_form_ajax_refs
)
def
test_form_flat_choices
():
app
,
db
,
admin
=
setup
()
class
Model
(
db
.
Document
):
name
=
db
.
StringField
(
max_length
=
20
,
choices
=
(
'a'
,
'b'
,
'c'
))
view
=
CustomModelView
(
Model
)
admin
.
add_view
(
view
)
form
=
view
.
create_form
()
eq_
(
form
.
name
.
choices
,
[(
'a'
,
'a'
),
(
'b'
,
'b'
),
(
'c'
,
'c'
)])
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