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
745620ad
Unverified
Commit
745620ad
authored
May 16, 2018
by
Serge S. Koval
Committed by
GitHub
May 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1623 from tiktuk/detail-formatters
Added formatters for detail view (fixes #1487)
parents
765e442f
ce66f22a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
base.py
flask_admin/model/base.py
+49
-1
typefmt.py
flask_admin/model/typefmt.py
+7
-0
No files found.
flask_admin/model/base.py
View file @
745620ad
...
@@ -263,6 +263,16 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -263,6 +263,16 @@ class BaseModelView(BaseView, ActionsMixin):
that macros are not supported.
that macros are not supported.
"""
"""
column_formatters_detail
=
None
"""
Dictionary of list view column formatters to be used for the detail view.
Defaults to column_formatters when set to None.
Functions the same way as column_formatters except
that macros are not supported.
"""
column_type_formatters
=
ObsoleteAttr
(
'column_type_formatters'
,
'list_type_formatters'
,
None
)
column_type_formatters
=
ObsoleteAttr
(
'column_type_formatters'
,
'list_type_formatters'
,
None
)
"""
"""
Dictionary of value type formatters to be used in the list view.
Dictionary of value type formatters to be used in the list view.
...
@@ -319,6 +329,18 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -319,6 +329,18 @@ class BaseModelView(BaseView, ActionsMixin):
Functions the same way as column_type_formatters.
Functions the same way as column_type_formatters.
"""
"""
column_type_formatters_detail
=
None
"""
Dictionary of value type formatters to be used in the detail view.
By default, two types are formatted:
1. ``None`` will be displayed as an empty string
2. ``list`` will be joined using ', '
Functions the same way as column_type_formatters.
"""
column_labels
=
ObsoleteAttr
(
'column_labels'
,
'rename_columns'
,
None
)
column_labels
=
ObsoleteAttr
(
'column_labels'
,
'rename_columns'
,
None
)
"""
"""
Dictionary where key is column name and value is string to display.
Dictionary where key is column name and value is string to display.
...
@@ -889,6 +911,9 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -889,6 +911,9 @@ class BaseModelView(BaseView, ActionsMixin):
if
self
.
column_formatters_export
is
None
:
if
self
.
column_formatters_export
is
None
:
self
.
column_formatters_export
=
self
.
column_formatters
self
.
column_formatters_export
=
self
.
column_formatters
if
self
.
column_formatters_detail
is
None
:
self
.
column_formatters_detail
=
self
.
column_formatters
# Type formatters
# Type formatters
if
self
.
column_type_formatters
is
None
:
if
self
.
column_type_formatters
is
None
:
self
.
column_type_formatters
=
dict
(
typefmt
.
BASE_FORMATTERS
)
self
.
column_type_formatters
=
dict
(
typefmt
.
BASE_FORMATTERS
)
...
@@ -896,6 +921,9 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -896,6 +921,9 @@ class BaseModelView(BaseView, ActionsMixin):
if
self
.
column_type_formatters_export
is
None
:
if
self
.
column_type_formatters_export
is
None
:
self
.
column_type_formatters_export
=
dict
(
typefmt
.
EXPORT_FORMATTERS
)
self
.
column_type_formatters_export
=
dict
(
typefmt
.
EXPORT_FORMATTERS
)
if
self
.
column_type_formatters_detail
is
None
:
self
.
column_type_formatters_detail
=
dict
(
typefmt
.
DETAIL_FORMATTERS
)
if
self
.
column_descriptions
is
None
:
if
self
.
column_descriptions
is
None
:
self
.
column_descriptions
=
dict
()
self
.
column_descriptions
=
dict
()
...
@@ -1803,6 +1831,26 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -1803,6 +1831,26 @@ class BaseModelView(BaseView, ActionsMixin):
self
.
column_type_formatters
,
self
.
column_type_formatters
,
)
)
@
contextfunction
def
get_detail_value
(
self
,
context
,
model
,
name
):
"""
Returns the value to be displayed in the detail view
:param context:
:py:class:`jinja2.runtime.Context`
:param model:
Model instance
:param name:
Field name
"""
return
self
.
_get_list_value
(
context
,
model
,
name
,
self
.
column_formatters_detail
,
self
.
column_type_formatters_detail
,
)
def
get_export_value
(
self
,
model
,
name
):
def
get_export_value
(
self
,
model
,
name
):
"""
"""
Returns the value to be displayed in export.
Returns the value to be displayed in export.
...
@@ -2103,7 +2151,7 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -2103,7 +2151,7 @@ class BaseModelView(BaseView, ActionsMixin):
return
self
.
render
(
template
,
return
self
.
render
(
template
,
model
=
model
,
model
=
model
,
details_columns
=
self
.
_details_columns
,
details_columns
=
self
.
_details_columns
,
get_value
=
self
.
get_
list
_value
,
get_value
=
self
.
get_
detail
_value
,
return_url
=
return_url
)
return_url
=
return_url
)
@
expose
(
'/delete/'
,
methods
=
(
'POST'
,))
@
expose
(
'/delete/'
,
methods
=
(
'POST'
,))
...
...
flask_admin/model/typefmt.py
View file @
745620ad
...
@@ -84,6 +84,13 @@ EXPORT_FORMATTERS = {
...
@@ -84,6 +84,13 @@ EXPORT_FORMATTERS = {
dict
:
dict_formatter
,
dict
:
dict_formatter
,
}
}
DETAIL_FORMATTERS
=
{
type
(
None
):
empty_formatter
,
list
:
list_formatter
,
dict
:
dict_formatter
,
}
if
Enum
is
not
None
:
if
Enum
is
not
None
:
BASE_FORMATTERS
[
Enum
]
=
enum_formatter
BASE_FORMATTERS
[
Enum
]
=
enum_formatter
EXPORT_FORMATTERS
[
Enum
]
=
enum_formatter
EXPORT_FORMATTERS
[
Enum
]
=
enum_formatter
DETAIL_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