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
115eb996
Commit
115eb996
authored
Dec 26, 2016
by
PJ Janse van Rensburg
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
git://github.com/algoo/flask-admin
into prs-to-merge
parents
b612215c
ee9305db
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
9 deletions
+36
-9
view.py
flask_admin/contrib/sqla/view.py
+31
-7
filters.py
flask_admin/model/filters.py
+4
-1
test_basic.py
flask_admin/tests/sqla/test_basic.py
+1
-1
No files found.
flask_admin/contrib/sqla/view.py
View file @
115eb996
...
...
@@ -628,9 +628,22 @@ class ModelView(BaseModelView):
column
=
columns
[
0
]
# If filter related to relation column (represented by
# relation_name.target_column) we collect here relation name
joined_column_name
=
None
if
'.'
in
name
:
joined_column_name
=
name
.
split
(
'.'
)[
0
]
# Join not needed for hybrid properties
if
(
not
is_hybrid_property
and
tools
.
need_join
(
self
.
model
,
column
.
table
)
and
name
not
in
self
.
column_labels
):
if
joined_column_name
:
visible_name
=
'
%
s /
%
s /
%
s'
%
(
joined_column_name
,
self
.
get_column_name
(
column
.
table
.
name
),
self
.
get_column_name
(
column
.
name
)
)
else
:
visible_name
=
'
%
s /
%
s'
%
(
self
.
get_column_name
(
column
.
table
.
name
),
self
.
get_column_name
(
column
.
name
)
...
...
@@ -657,10 +670,19 @@ class ModelView(BaseModelView):
options
=
self
.
column_choices
.
get
(
name
),
)
key_name
=
column
# In case of filter related to relation column filter key
# must be named with relation name (to prevent following same
# target column to replace previous)
if
joined_column_name
:
key_name
=
"{0}.{1}"
.
format
(
joined_column_name
,
column
)
for
f
in
flt
:
f
.
key_name
=
key_name
if
joins
:
self
.
_filter_joins
[
column
]
=
joins
self
.
_filter_joins
[
key_name
]
=
joins
elif
not
is_hybrid_property
and
tools
.
need_join
(
self
.
model
,
column
.
table
):
self
.
_filter_joins
[
column
]
=
[
column
.
table
]
self
.
_filter_joins
[
key_name
]
=
[
column
.
table
]
return
flt
...
...
@@ -900,7 +922,9 @@ class ModelView(BaseModelView):
# Figure out joins
if
isinstance
(
flt
,
sqla_filters
.
BaseSQLAFilter
):
path
=
self
.
_filter_joins
.
get
(
flt
.
column
,
[])
# If no key_name is specified, use filter column as filter key
filter_key
=
flt
.
key_name
or
flt
.
column
path
=
self
.
_filter_joins
.
get
(
filter_key
,
[])
query
,
joins
,
alias
=
self
.
_apply_path_joins
(
query
,
joins
,
path
,
inner_join
=
False
)
...
...
flask_admin/model/filters.py
View file @
115eb996
...
...
@@ -8,7 +8,7 @@ class BaseFilter(object):
"""
Base filter class.
"""
def
__init__
(
self
,
name
,
options
=
None
,
data_type
=
None
):
def
__init__
(
self
,
name
,
options
=
None
,
data_type
=
None
,
key_name
=
None
):
"""
Constructor.
...
...
@@ -18,10 +18,13 @@ class BaseFilter(object):
List of fixed options. If provided, will use drop down instead of textbox.
:param data_type:
Client-side widget type to use.
:param key_name:
Optional name who represent this filter.
"""
self
.
name
=
name
self
.
options
=
options
self
.
data_type
=
data_type
self
.
key_name
=
key_name
def
get_options
(
self
,
view
):
"""
...
...
flask_admin/tests/sqla/test_basic.py
View file @
115eb996
...
...
@@ -640,7 +640,7 @@ def test_column_filters():
view
=
CustomModelView
(
Model2
,
db
.
session
,
column_filters
=
[
'model1.bool_field'
])
eq_
([(
f
[
'index'
],
f
[
'operation'
])
for
f
in
view
.
_filter_groups
[
u'Model1 / Bool Field'
]],
eq_
([(
f
[
'index'
],
f
[
'operation'
])
for
f
in
view
.
_filter_groups
[
u'
model1 /
Model1 / Bool Field'
]],
[
(
0
,
'equals'
),
(
1
,
'not equal'
),
...
...
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