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
c81b07f9
Commit
c81b07f9
authored
Mar 22, 2016
by
David Baumgold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default type formatters for Enum
parent
c945f214
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 @
c81b07f9
from
jinja2
import
Markup
from
jinja2
import
Markup
from
flask_admin._compat
import
text_type
from
flask_admin._compat
import
text_type
try
:
from
enum
import
Enum
except
ImportError
:
Enum
=
None
def
null_formatter
(
view
,
value
):
def
null_formatter
(
view
,
value
):
...
@@ -44,6 +48,16 @@ def list_formatter(view, values):
...
@@ -44,6 +48,16 @@ def list_formatter(view, values):
return
u', '
.
join
(
text_type
(
v
)
for
v
in
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
=
{
BASE_FORMATTERS
=
{
type
(
None
):
empty_formatter
,
type
(
None
):
empty_formatter
,
bool
:
bool_formatter
,
bool
:
bool_formatter
,
...
@@ -54,3 +68,7 @@ EXPORT_FORMATTERS = {
...
@@ -54,3 +68,7 @@ EXPORT_FORMATTERS = {
type
(
None
):
empty_formatter
,
type
(
None
):
empty_formatter
,
list
:
list_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