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
120f3cbc
Commit
120f3cbc
authored
Feb 24, 2015
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #795 from pawl/integersearch
Allow searching non-text SQLAlchemy column types
parents
90d4a1b1
bdad7fa8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
+15
-15
view.py
flask_admin/contrib/sqla/view.py
+1
-6
test_basic.py
flask_admin/tests/sqla/test_basic.py
+14
-9
No files found.
flask_admin/contrib/sqla/view.py
View file @
120f3cbc
...
@@ -80,8 +80,7 @@ class ModelView(BaseModelView):
...
@@ -80,8 +80,7 @@ class ModelView(BaseModelView):
'searchable_columns'
,
'searchable_columns'
,
None
)
None
)
"""
"""
Collection of the searchable columns. Only text-based columns
Collection of the searchable columns.
are searchable (`String`, `Unicode`, `Text`, `UnicodeText`).
Example::
Example::
...
@@ -491,10 +490,6 @@ class ModelView(BaseModelView):
...
@@ -491,10 +490,6 @@ class ModelView(BaseModelView):
for
column
in
self
.
_get_columns_for_field
(
attr
):
for
column
in
self
.
_get_columns_for_field
(
attr
):
column_type
=
type
(
column
.
type
)
.
__name__
column_type
=
type
(
column
.
type
)
.
__name__
if
not
self
.
is_text_column_type
(
column_type
):
raise
Exception
(
'Can only search on text columns. '
+
'Failed to setup search for "
%
s"'
%
p
)
self
.
_search_fields
.
append
(
column
)
self
.
_search_fields
.
append
(
column
)
# Store joins, avoid duplicates
# Store joins, avoid duplicates
...
...
flask_admin/tests/sqla/test_basic.py
View file @
120f3cbc
...
@@ -253,27 +253,32 @@ def test_column_searchable_list():
...
@@ -253,27 +253,32 @@ def test_column_searchable_list():
Model1
,
Model2
=
create_models
(
db
)
Model1
,
Model2
=
create_models
(
db
)
view
=
CustomModelView
(
Model
1
,
db
.
session
,
view
=
CustomModelView
(
Model
2
,
db
.
session
,
column_searchable_list
=
[
'
test1'
,
'test2
'
])
column_searchable_list
=
[
'
string_field'
,
'int_field
'
])
admin
.
add_view
(
view
)
admin
.
add_view
(
view
)
eq_
(
view
.
_search_supported
,
True
)
eq_
(
view
.
_search_supported
,
True
)
eq_
(
len
(
view
.
_search_fields
),
2
)
eq_
(
len
(
view
.
_search_fields
),
2
)
ok_
(
isinstance
(
view
.
_search_fields
[
0
],
db
.
Column
))
ok_
(
isinstance
(
view
.
_search_fields
[
0
],
db
.
Column
))
ok_
(
isinstance
(
view
.
_search_fields
[
1
],
db
.
Column
))
ok_
(
isinstance
(
view
.
_search_fields
[
1
],
db
.
Column
))
eq_
(
view
.
_search_fields
[
0
]
.
name
,
'
test1
'
)
eq_
(
view
.
_search_fields
[
0
]
.
name
,
'
string_field
'
)
eq_
(
view
.
_search_fields
[
1
]
.
name
,
'
test2
'
)
eq_
(
view
.
_search_fields
[
1
]
.
name
,
'
int_field
'
)
db
.
session
.
add
(
Model
1
(
'model1'
))
db
.
session
.
add
(
Model
2
(
'model1-test'
,
5000
))
db
.
session
.
add
(
Model
1
(
'model2'
))
db
.
session
.
add
(
Model
2
(
'model2-test'
,
9000
))
db
.
session
.
commit
()
db
.
session
.
commit
()
client
=
app
.
test_client
()
client
=
app
.
test_client
()
rv
=
client
.
get
(
'/admin/model1/?search=model1'
)
rv
=
client
.
get
(
'/admin/model2/?search=model1'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
ok_
(
'model1-test'
in
data
)
ok_
(
'model2-test'
not
in
data
)
rv
=
client
.
get
(
'/admin/model2/?search=9000'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
data
=
rv
.
data
.
decode
(
'utf-8'
)
ok_
(
'model1
'
in
data
)
ok_
(
'model1
-test'
not
in
data
)
ok_
(
'model2
'
not
in
data
)
ok_
(
'model2
-test'
in
data
)
def
test_complex_searchable_list
():
def
test_complex_searchable_list
():
...
...
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