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
05262c19
Commit
05262c19
authored
Feb 07, 2016
by
Paul Brown
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1194 from toddetzel/master
More Flexible Exports Without Exceptions
parents
c0f904a5
433206a0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
3 deletions
+78
-3
base.py
flask_admin/model/base.py
+8
-3
test_model.py
flask_admin/tests/test_model.py
+70
-0
No files found.
flask_admin/model/base.py
View file @
05262c19
...
@@ -2015,11 +2015,16 @@ class BaseModelView(BaseView, ActionsMixin):
...
@@ -2015,11 +2015,16 @@ class BaseModelView(BaseView, ActionsMixin):
# Macros in column_formatters are not supported.
# Macros in column_formatters are not supported.
# Macros will have a function name 'inner'
# Macros will have a function name 'inner'
# This causes non-macro functions named 'inner' not work.
# This causes non-macro functions named 'inner' not work.
for
col
,
func
in
iteritems
(
self
.
column_formatters
):
for
col
,
func
in
iteritems
(
self
.
column_formatters_export
):
# skip checking columns not being exported
if
col
not
in
[
col
for
col
,
_
in
self
.
_export_columns
]:
continue
if
func
.
__name__
==
'inner'
:
if
func
.
__name__
==
'inner'
:
raise
NotImplementedError
(
raise
NotImplementedError
(
'Macros not implemented. Override with '
'Macros are not implemented in export. Exclude column in'
'column_formatters_export. Column:
%
s'
%
(
col
,)
' column_formatters_export, column_export_list, or '
' column_export_exclude_list. Column:
%
s'
%
(
col
,)
)
)
# Grab parameters from URL
# Grab parameters from URL
...
...
flask_admin/tests/test_model.py
View file @
05262c19
...
@@ -656,3 +656,73 @@ def test_export_csv():
...
@@ -656,3 +656,73 @@ def test_export_csv():
rv
=
client
.
get
(
'/admin/macro_exception/export/csv/'
)
rv
=
client
.
get
(
'/admin/macro_exception/export/csv/'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
eq_
(
rv
.
status_code
,
500
)
eq_
(
rv
.
status_code
,
500
)
# We should be able to specify column_formatters_export
# and not get an exception if a column_formatter is using a macro
def
export_formatter
(
v
,
c
,
m
,
p
):
return
m
.
col1
if
m
else
''
view
=
MockModelView
(
Model
,
view_data
,
can_export
=
True
,
column_list
=
[
'col1'
,
'col2'
],
column_formatters
=
dict
(
col1
=
macro
(
'render_macro'
)),
column_formatters_export
=
dict
(
col1
=
export_formatter
),
endpoint
=
"macro_exception_formatter_override"
)
admin
.
add_view
(
view
)
rv
=
client
.
get
(
'/admin/macro_exception_formatter_override/export/csv/'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
eq_
(
rv
.
status_code
,
200
)
ok_
(
"Col1,Col2
\r\n
"
"col1_1,1
\r\n
"
"col1_2,2
\r\n
"
",3
\r\n
"
==
data
)
# We should not get an exception if a column_formatter is
# using a macro but it is on the column_export_exclude_list
view
=
MockModelView
(
Model
,
view_data
,
can_export
=
True
,
column_list
=
[
'col1'
,
'col2'
],
column_formatters
=
dict
(
col1
=
macro
(
'render_macro'
)),
column_export_exclude_list
=
[
'col1'
],
endpoint
=
"macro_exception_exclude_override"
)
admin
.
add_view
(
view
)
rv
=
client
.
get
(
'/admin/macro_exception_exclude_override/export/csv/'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
eq_
(
rv
.
status_code
,
200
)
ok_
(
"Col2
\r\n
"
"1
\r\n
"
"2
\r\n
"
"3
\r\n
"
==
data
)
# When we use column_export_list to hide the macro field
# we should not get an exception
view
=
MockModelView
(
Model
,
view_data
,
can_export
=
True
,
column_list
=
[
'col1'
,
'col2'
],
column_formatters
=
dict
(
col1
=
macro
(
'render_macro'
)),
column_export_list
=
[
'col2'
],
endpoint
=
"macro_exception_list_override"
)
admin
.
add_view
(
view
)
rv
=
client
.
get
(
'/admin/macro_exception_list_override/export/csv/'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
eq_
(
rv
.
status_code
,
200
)
ok_
(
"Col2
\r\n
"
"1
\r\n
"
"2
\r\n
"
"3
\r\n
"
==
data
)
# If they define a macro on the column_formatters_export list
# then raise an exception
view
=
MockModelView
(
Model
,
view_data
,
can_export
=
True
,
column_list
=
[
'col1'
,
'col2'
],
column_formatters
=
dict
(
col1
=
macro
(
'render_macro'
)),
endpoint
=
"macro_exception_macro_override"
)
admin
.
add_view
(
view
)
rv
=
client
.
get
(
'/admin/macro_exception_macro_override/export/csv/'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
eq_
(
rv
.
status_code
,
500
)
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