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
782b01dc
Commit
782b01dc
authored
Feb 07, 2016
by
Paul Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
throw error when adding a related table's column object to column_sortable_list
parent
3eda9c86
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
38 deletions
+31
-38
form.py
flask_admin/contrib/sqla/form.py
+1
-1
view.py
flask_admin/contrib/sqla/view.py
+6
-1
test_basic.py
flask_admin/tests/sqla/test_basic.py
+24
-36
No files found.
flask_admin/contrib/sqla/form.py
View file @
782b01dc
...
...
@@ -9,7 +9,7 @@ from flask_admin.model.form import (converts, ModelConverterBase,
from
flask_admin.model.fields
import
AjaxSelectField
,
AjaxSelectMultipleField
from
flask_admin.model.helpers
import
prettify_name
from
flask_admin._backwards
import
get_property
from
flask_admin._compat
import
iteritems
,
text_type
from
flask_admin._compat
import
iteritems
from
.validators
import
Unique
from
.fields
import
(
QuerySelectField
,
QuerySelectMultipleField
,
...
...
flask_admin/contrib/sqla/view.py
View file @
782b01dc
...
...
@@ -475,10 +475,15 @@ class ModelView(BaseModelView):
column
,
path
=
tools
.
get_field_with_path
(
self
.
model
,
c
)
column_name
=
c
if
path
:
if
path
and
hasattr
(
path
[
0
],
'property'
)
:
# column is in another table, use full path as column_name
column_name
=
text_type
(
c
)
self
.
_sortable_joins
[
column_name
]
=
path
elif
path
:
raise
Exception
(
"For sorting columns in a related table, "
"column_sortable_list requires a string "
"like '<relation name>.<column name>'. "
"Failed on: {0}"
.
format
(
c
))
else
:
# column is in same table, use only model attribute name
column_name
=
column
.
key
...
...
flask_admin/tests/sqla/test_basic.py
View file @
782b01dc
...
...
@@ -271,21 +271,6 @@ def test_complex_list_columns():
data
=
rv
.
data
.
decode
(
'utf-8'
)
ok_
(
'model1_val1'
in
data
)
# TODO: Allow providing a list of related models
"""
# test column_list with a list of models on a relation
view2 = CustomModelView(M2, db.session, endpoint='model2_2',
column_list=[M1.test1])
admin.add_view(view2)
client = app.test_client()
rv = client.get('/admin/model2_2/')
eq_(rv.status_code, 200)
data = rv.data.decode('utf-8')
ok_('model1_val1' in data)
"""
def
test_exclude_columns
():
app
,
db
,
admin
=
setup
()
...
...
@@ -1712,31 +1697,23 @@ def test_complex_sort():
rv
=
client
.
get
(
'/admin/model2/?sort=1'
)
eq_
(
rv
.
status_code
,
200
)
# test sorting on relation object - M2.string_field
view2
=
CustomModelView
(
M1
,
db
.
session
,
column_list
=
[
'model2.string_field'
],
column_sortable_list
=
[
M2
.
string_field
])
admin
.
add_view
(
view2
)
client
=
app
.
test_client
()
rv
=
client
.
get
(
'/admin/model1/?sort=1'
)
eq_
(
rv
.
status_code
,
200
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
ok_
(
'Sort by'
in
data
)
@
raises
(
Exception
)
def
test_complex_sort_exception
():
app
,
db
,
admin
=
setup
(
)
M1
,
M2
=
create_models
(
db
)
# test sorting on relations with model in column_list
view3
=
CustomModelView
(
M1
,
db
.
session
,
endpoint
=
"model1_2"
,
column_list
=
[
M2
.
string_field
],
column_sortable_list
=
[
M2
.
string_field
])
admin
.
add_view
(
view3
)
# test column_sortable_list on a related table's column object
view
=
CustomModelView
(
M2
,
db
.
session
,
endpoint
=
"model2_3"
,
column_sortable_list
=
[
M1
.
test1
])
admin
.
add_view
(
view
)
client
=
app
.
test_client
()
sort_column
=
view
.
_get_column_by_idx
(
0
)[
0
]
_
,
data
=
view
.
get_list
(
0
,
sort_column
,
False
,
None
,
None
)
rv
=
client
.
get
(
'/admin/model1_2/?sort=1'
)
eq_
(
rv
.
status_code
,
200
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
ok_
(
'Sort by'
in
data
)
eq_
(
len
(
data
),
2
)
eq_
(
data
[
0
]
.
model1
.
test1
,
'a'
)
eq_
(
data
[
1
]
.
model1
.
test1
,
'b'
)
def
test_default_complex_sort
():
...
...
@@ -1762,6 +1739,17 @@ def test_default_complex_sort():
eq_
(
data
[
0
]
.
model1
.
test1
,
'a'
)
eq_
(
data
[
1
]
.
model1
.
test1
,
'b'
)
# test column_default_sort on a related table's column object
view2
=
CustomModelView
(
M2
,
db
.
session
,
endpoint
=
"model2_2"
,
column_default_sort
=
(
M1
.
test1
,
False
))
admin
.
add_view
(
view2
)
_
,
data
=
view2
.
get_list
(
0
,
None
,
None
,
None
,
None
)
eq_
(
len
(
data
),
2
)
eq_
(
data
[
0
]
.
model1
.
test1
,
'a'
)
eq_
(
data
[
1
]
.
model1
.
test1
,
'b'
)
def
test_extra_fields
():
app
,
db
,
admin
=
setup
()
...
...
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