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
323405e6
Commit
323405e6
authored
Dec 16, 2013
by
Bryan Hoyt
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'named-filter-forms'
Conflicts: flask_admin/model/base.py
parents
41a68dde
a2d35b3a
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
190 additions
and
152 deletions
+190
-152
list.html
examples/layout/templates/list.html
+1
-1
base.py
flask_admin/model/base.py
+120
-70
filters.js
flask_admin/static/admin/js/filters.js
+13
-16
layout.html
flask_admin/templates/admin/model/layout.html
+11
-11
list.html
flask_admin/templates/admin/model/list.html
+2
-4
test_basic.py
flask_admin/tests/sqlamodel/test_basic.py
+41
-48
test_model.py
flask_admin/tests/test_model.py
+2
-2
No files found.
examples/layout/templates/list.html
View file @
323405e6
...
@@ -31,4 +31,4 @@
...
@@ -31,4 +31,4 @@
{% endblock %}
{% endblock %}
{% block model_menu_bar %}
{% block model_menu_bar %}
{% endblock %}
{% endblock %}
\ No newline at end of file
flask_admin/model/base.py
View file @
323405e6
This diff is collapsed.
Click to expand it.
flask_admin/static/admin/js/filters.js
View file @
323405e6
var
AdminFilters
=
function
(
element
,
filters_element
,
operations
,
options
,
types
)
{
var
AdminFilters
=
function
(
element
,
filters_element
,
filters_by_group
)
{
var
$root
=
$
(
element
);
var
$root
=
$
(
element
);
var
$container
=
$
(
'.filters'
,
$root
);
var
$container
=
$
(
'.filters'
,
$root
);
var
lastCount
=
0
;
var
lastCount
=
0
;
...
@@ -23,7 +23,7 @@ var AdminFilters = function(element, filters_element, operations, options, types
...
@@ -23,7 +23,7 @@ var AdminFilters = function(element, filters_element, operations, options, types
return
false
;
return
false
;
}
}
function
addFilter
(
name
,
op
)
{
function
addFilter
(
name
,
subfilters
)
{
var
$el
=
$
(
'<tr />'
).
appendTo
(
$container
);
var
$el
=
$
(
'<tr />'
).
appendTo
(
$container
);
// Filter list
// Filter list
...
@@ -41,8 +41,8 @@ var AdminFilters = function(element, filters_element, operations, options, types
...
@@ -41,8 +41,8 @@ var AdminFilters = function(element, filters_element, operations, options, types
var
$select
=
$
(
'<select class="filter-op" />'
)
var
$select
=
$
(
'<select class="filter-op" />'
)
.
change
(
changeOperation
);
.
change
(
changeOperation
);
$
(
op
).
each
(
function
()
{
$
(
subfilters
).
each
(
function
()
{
$select
.
append
(
$
(
'<option/>'
).
attr
(
'value'
,
this
[
0
]).
text
(
this
[
1
]
));
$select
.
append
(
$
(
'<option/>'
).
attr
(
'value'
,
this
.
label
).
text
(
this
.
operation
));
});
});
$el
.
append
(
$el
.
append
(
...
@@ -51,16 +51,14 @@ var AdminFilters = function(element, filters_element, operations, options, types
...
@@ -51,16 +51,14 @@ var AdminFilters = function(element, filters_element, operations, options, types
$select
.
select2
({
width
:
'resolve'
});
$select
.
select2
({
width
:
'resolve'
});
// Input
var
optId
=
op
[
0
][
0
];
var
$field
;
var
$field
;
if
(
optId
in
options
)
{
var
firstFilter
=
subfilters
[
0
];
if
(
firstFilter
.
options
)
{
$field
=
$
(
'<select class="filter-val" />'
)
$field
=
$
(
'<select class="filter-val" />'
)
.
attr
(
'name'
,
'flt'
+
lastCount
+
'_'
+
optId
);
.
attr
(
'name'
,
'flt'
+
lastCount
+
'_'
+
firstFilter
.
label
);
$
(
options
[
optId
]
).
each
(
function
()
{
$
(
firstFilter
.
options
).
each
(
function
()
{
$field
.
append
(
$
(
'<option/>'
)
$field
.
append
(
$
(
'<option/>'
)
.
val
(
this
[
0
]).
text
(
this
[
1
]));
.
val
(
this
[
0
]).
text
(
this
[
1
]));
});
});
...
@@ -70,13 +68,13 @@ var AdminFilters = function(element, filters_element, operations, options, types
...
@@ -70,13 +68,13 @@ var AdminFilters = function(element, filters_element, operations, options, types
}
else
}
else
{
{
$field
=
$
(
'<input type="text" class="filter-val" />'
)
$field
=
$
(
'<input type="text" class="filter-val" />'
)
.
attr
(
'name'
,
'flt'
+
lastCount
+
'_'
+
optId
);
.
attr
(
'name'
,
'flt'
+
lastCount
+
'_'
+
firstFilter
.
label
);
$el
.
append
(
$
(
'<td/>'
).
append
(
$field
));
$el
.
append
(
$
(
'<td/>'
).
append
(
$field
));
}
}
if
(
optId
in
types
)
{
if
(
firstFilter
.
data_type
)
{
$field
.
attr
(
'data-role'
,
types
[
optId
]
);
$field
.
attr
(
'data-role'
,
firstFilter
.
data_type
);
faForm
.
applyStyle
(
$field
,
types
[
optId
]
);
faForm
.
applyStyle
(
$field
,
firstFilter
.
data_type
);
}
}
lastCount
+=
1
;
lastCount
+=
1
;
...
@@ -84,8 +82,7 @@ var AdminFilters = function(element, filters_element, operations, options, types
...
@@ -84,8 +82,7 @@ var AdminFilters = function(element, filters_element, operations, options, types
$
(
'a.filter'
,
filters_element
).
click
(
function
()
{
$
(
'a.filter'
,
filters_element
).
click
(
function
()
{
var
name
=
$
(
this
).
text
().
trim
();
var
name
=
$
(
this
).
text
().
trim
();
addFilter
(
name
,
filters_by_group
[
name
]);
addFilter
(
name
,
operations
[
name
]);
$
(
'button'
,
$root
).
show
();
$
(
'button'
,
$root
).
show
();
...
...
flask_admin/templates/admin/model/layout.html
View file @
323405e6
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<ul
class=
"dropdown-menu field-filters"
>
<ul
class=
"dropdown-menu field-filters"
>
{% for k in filter_groups %}
{% for k in filter_groups %}
<li>
<li>
<a
href=
"javascript:void(0)"
class=
"filter"
onclick=
"return false;"
>
{{ k
[0]
}}
</a>
<a
href=
"javascript:void(0)"
class=
"filter"
onclick=
"return false;"
>
{{ k }}
</a>
</li>
</li>
{% endfor %}
{% endfor %}
</ul>
</ul>
...
@@ -23,29 +23,29 @@
...
@@ -23,29 +23,29 @@
<table
class=
"filters"
>
<table
class=
"filters"
>
{%- for i, flt in enumerate(active_filters) -%}
{%- for i, flt in enumerate(active_filters) -%}
<tr>
<tr>
{% set filter = admin_view._filters[flt[0]] %}
{% set filter = filters[flt[0]] %}
{%- set filter_label = admin_view.unique_filter_label(filter) -%}
<td>
<td>
<a
href=
"javascript:void(0)"
class=
"btn remove-filter"
title=
"{{ _gettext('Remove Filter') }}"
>
<a
href=
"javascript:void(0)"
class=
"btn remove-filter"
title=
"{{ _gettext('Remove Filter') }}"
>
<span
class=
"close-icon"
>
×
</span>
{{ filter
s[flt[0]]
}}
<span
class=
"close-icon"
>
×
</span>
{{ filter
.name
}}
</a>
</a>
</td>
</td>
<td>
<td>
<select
class=
"filter-op"
data-role=
"select2"
>
<select
class=
"filter-op"
data-role=
"select2"
>
{% for
op in admin_view._filter_dict
[filter.name] %}
{% for
subfilter in filter_groups
[filter.name] %}
<option
value=
"{{
op[0] }}"
{%
if
flt
[
0
]
==
op
[
0
]
%}
selected=
"selected"
{%
endif
%}
>
{{ op[1]
}}
</option>
<option
value=
"{{
subfilter.label }}"
{%
if
subfilter
.
label =
=
filter_label
%}
selected=
"selected"
{%
endif
%}
>
{{ subfilter.operation
}}
</option>
{% endfor %}
{% endfor %}
</select>
</select>
</td>
</td>
<td>
<td>
{%- set data = filter_data.get(flt[0]) -%}
{%- if filter.options -%}
{%- if data -%}
<select
name=
"flt{{ i }}_{{ filter_label }}"
class=
"filter-val"
data-role=
"select2"
>
<select
name=
"flt{{ i }}_{{ flt[0] }}"
class=
"filter-val"
data-role=
"select2"
>
{%- for o in filter.options %}
{%- for d in data %}
<option
value=
"{{ o[0] }}"
{%
if
flt
[
1
]
==
o
[
0
]
%}
selected
{%
endif
%}
>
{{ o[1] }}
</option>
<option
value=
"{{ d[0] }}"
{%
if
flt
[
1
]
==
d
[
0
]
%}
selected
{%
endif
%}
>
{{ d[1] }}
</option>
{%- endfor %}
{%- endfor %}
</select>
</select>
{%- else -%}
{%- else -%}
<input
name=
"flt{{ i }}_{{ f
lt[0] }}"
type=
"text"
value=
"{{ flt[1] or '' }}"
class=
"filter-val"
{%
if
flt
[
0
]
in
filter_types
%}
data-role=
"{{ filter_types[flt[0]]
}}"
{%
endif
%}
></input>
<input
name=
"flt{{ i }}_{{ f
ilter_label }}"
type=
"text"
value=
"{{ flt[1] or '' }}"
class=
"filter-val"
{%
if
filter
.
data_type
%}
data-role=
"{{ filter.data_type
}}"
{%
endif
%}
></input>
{%- endif -%}
{%- endif -%}
</td>
</td>
</tr>
</tr>
...
...
flask_admin/templates/admin/model/list.html
View file @
323405e6
...
@@ -157,12 +157,10 @@
...
@@ -157,12 +157,10 @@
html
:
true
,
html
:
true
,
placement
:
'bottom'
placement
:
'bottom'
});
});
{
%
if
filter_groups
is
not
none
and
filter_data
is
not
none
%
}
{
%
if
filter_groups
is
not
none
%
}
var
filter
=
new
AdminFilters
(
var
filter
=
new
AdminFilters
(
'#filter_form'
,
'.field-filters'
,
'#filter_form'
,
'.field-filters'
,
{{
admin_view
.
_get_filter_dict
()
|
tojson
|
safe
}},
{{
filter_groups
|
tojson
|
safe
}}
{{
filter_data
|
tojson
|
safe
}},
{{
filter_types
|
tojson
|
safe
}}
);
);
{
%
endif
%
}
{
%
endif
%
}
})(
jQuery
);
})(
jQuery
);
...
...
flask_admin/tests/sqlamodel/test_basic.py
View file @
323405e6
...
@@ -233,61 +233,52 @@ def test_column_filters():
...
@@ -233,61 +233,52 @@ def test_column_filters():
eq_
(
len
(
view
.
_filters
),
4
)
eq_
(
len
(
view
.
_filters
),
4
)
eq_
(
view
.
_filter_dict
,
{
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Test1'
]
],
u'Test1'
:
[
[(
'0'
,
u'equals'
),
(
0
,
u'equals'
),
(
'1'
,
u'not equal'
),
(
1
,
u'not equal'
),
(
'2'
,
u'contains'
),
(
2
,
u'contains'
),
(
'3'
,
u'not contains'
)])
(
3
,
u'not contains'
)
]})
# Test filter that references property
# Test filter that references property
view
=
CustomModelView
(
Model2
,
db
.
session
,
view
=
CustomModelView
(
Model2
,
db
.
session
,
column_filters
=
[
'model1'
])
column_filters
=
[
'model1'
])
eq_
(
view
.
_filter_dict
,
{
u'Model1 / Test1'
:
[
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Model1 / Test1'
]
],
(
0
,
u'equals'
),
[(
'0'
,
u'equals'
),
(
1
,
u'not equal'
),
(
'1'
,
u'not equal'
),
(
2
,
u'contains'
),
(
'2'
,
u'contains'
),
(
3
,
u'not contains'
)
(
'3'
,
u'not contains'
)])
],
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Model1 / Test2'
]
],
'Model1 / Test2'
:
[
[(
'4'
,
u'equals'
),
(
4
,
'equals'
),
(
'5'
,
u'not equal'
),
(
5
,
'not equal'
),
(
'6'
,
u'contains'
),
(
6
,
'contains'
),
(
'7'
,
u'not contains'
)])
(
7
,
'not contains'
)
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Model1 / Test3'
]
],
],
[(
'8'
,
u'equals'
),
u'Model1 / Test3'
:
[
(
'9'
,
u'not equal'
),
(
8
,
u'equals'
),
(
'10'
,
u'contains'
),
(
9
,
u'not equal'
),
(
'11'
,
u'not contains'
)])
(
10
,
u'contains'
),
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Model1 / Test4'
]
],
(
11
,
u'not contains'
)
[(
'12'
,
u'equals'
),
],
(
'13'
,
u'not equal'
),
u'Model1 / Test4'
:
[
(
'14'
,
u'contains'
),
(
12
,
u'equals'
),
(
'15'
,
u'not contains'
)])
(
13
,
u'not equal'
),
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Model1 / Bool Field'
]
],
(
14
,
u'contains'
),
[(
'16'
,
u'equals'
),
(
15
,
u'not contains'
)
(
'17'
,
u'not equal'
)])
],
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Model1 / Enum Field'
]
],
u'Model1 / Bool Field'
:
[
[(
'18'
,
u'equals'
),
(
16
,
u'equals'
),
(
'19'
,
u'not equal'
)])
(
17
,
u'not equal'
),
],
u'Model1 / Enum Field'
:
[
(
18
,
u'equals'
),
(
19
,
u'not equal'
),
]})
# Test filter with a dot
# Test filter with a dot
view
=
CustomModelView
(
Model2
,
db
.
session
,
view
=
CustomModelView
(
Model2
,
db
.
session
,
column_filters
=
[
'model1.bool_field'
])
column_filters
=
[
'model1.bool_field'
])
eq_
(
view
.
_filter_dict
,
{
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Model1 / Bool Field'
]
],
'Model1 / Bool Field'
:
[
[(
'0'
,
u'equals'
),
(
0
,
'equals'
),
(
'1'
,
u'not equal'
)])
(
1
,
'not equal'
),
]})
# Fill DB
# Fill DB
model1_obj1
=
Model1
(
'model1_obj1'
,
bool_field
=
True
)
model1_obj1
=
Model1
(
'model1_obj1'
,
bool_field
=
True
)
...
@@ -324,9 +315,11 @@ def test_column_filters():
...
@@ -324,9 +315,11 @@ def test_column_filters():
column_filters
=
[
'int_field'
])
column_filters
=
[
'int_field'
])
admin
.
add_view
(
view
)
admin
.
add_view
(
view
)
eq_
(
view
.
_filter_dict
,
{
'Int Field'
:
[(
0
,
'equals'
),
(
1
,
'not equal'
),
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'Int Field'
]
],
(
2
,
'greater than'
),
(
3
,
'smaller than'
)]})
[(
'0'
,
u'equals'
),
(
'1'
,
u'not equal'
),
(
'2'
,
u'greater than'
),
(
'3'
,
u'smaller than'
)])
#Test filters to joined table field
#Test filters to joined table field
view
=
CustomModelView
(
view
=
CustomModelView
(
...
...
flask_admin/tests/test_model.py
View file @
323405e6
...
@@ -302,8 +302,8 @@ def test_column_filters():
...
@@ -302,8 +302,8 @@ def test_column_filters():
eq_
(
view
.
_filters
[
0
]
.
name
,
'col1'
)
eq_
(
view
.
_filters
[
0
]
.
name
,
'col1'
)
eq_
(
view
.
_filters
[
1
]
.
name
,
'col2'
)
eq_
(
view
.
_filters
[
1
]
.
name
,
'col2'
)
eq_
(
view
.
_filter_dict
,
{
'col1'
:
[(
0
,
'test'
)],
eq_
(
[
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'col1'
]
],
[(
'0'
,
'test'
)])
'col2'
:
[(
1
,
'test'
)]}
)
eq_
([
(
f
[
'label'
],
f
[
'operation'
])
for
f
in
view
.
_flattened_filters_by_group
[
'col2'
]
],
[(
'1'
,
'test'
)]
)
# TODO: Make calls with filters
# TODO: Make calls with filters
...
...
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