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
32921060
Commit
32921060
authored
Mar 27, 2016
by
Paul Brown
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1236 from singingwolfboy/enum-typefmt
Add default type formatters for Enum
parents
61bc990c
c81b07f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
typefmt.py
flask_admin/model/typefmt.py
+18
-0
No files found.
flask_admin/model/typefmt.py
View file @
32921060
from
jinja2
import
Markup
from
flask_admin._compat
import
text_type
try
:
from
enum
import
Enum
except
ImportError
:
Enum
=
None
def
null_formatter
(
view
,
value
):
...
...
@@ -44,6 +48,16 @@ def list_formatter(view, values):
return
u', '
.
join
(
text_type
(
v
)
for
v
in
values
)
def
enum_formatter
(
view
,
value
):
"""
Return the name of the enumerated member.
:param value:
Value to check
"""
return
value
.
name
BASE_FORMATTERS
=
{
type
(
None
):
empty_formatter
,
bool
:
bool_formatter
,
...
...
@@ -54,3 +68,7 @@ EXPORT_FORMATTERS = {
type
(
None
):
empty_formatter
,
list
:
list_formatter
,
}
if
Enum
is
not
None
:
BASE_FORMATTERS
[
Enum
]
=
enum_formatter
EXPORT_FORMATTERS
[
Enum
]
=
enum_formatter
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